While it makes sense to use a h1
as a title for a modal because you visually appear to be in a new content on the web page, you are still swimming in the same context- so for a screen reader user, a h2
is a better accessible user experience. This will prevent confusion for a screen reader user as you're navigating through the same context.
Review this user flow as a no-vision screen reader user.
- User opens a new web page with the
Contact Us
page title. Contact Us is a h1
. SR will read, "Heading level 1, Contact Us. You are currently on a heading level 1".
- User tabs through or uses the keyboard arrow keys to type their information in the form gracefully.
- User finally tabs or navigates through the "Submit" button and clicks enter.
- A dialog or modal opens up, with a title "Confirmation" and reads "Are you sure you would like to submit?".
- If you use a
h1
, you'll signal to the SR user that you're on a new page, new content, new context.
- While if you use a
h2
, you'll signal to the SR user that you're on the same page, same context on submitting your form, but different content- you're in a modal- as a header will convey.
Also note, that if you use semantic html, with appropriate roles and states in your markup, your Screen Reader will correctly tell your user that they are in a modal dialog.
QuentinC is correct that "never in WCAG it is said that there must only be a single H1`. But this is the beauty of WCAG- it will never tell you what to do, but it will guide you, what not to do.
Here's an example of the Dialog widget pattern in the w3.org website: https://www.w3.org/TR/wai-aria-practices-1.1/examples/dialog-modal/dialog.html
Here's some more context on conveying information using semantic markup: https://www.w3.org/WAI/WCAG21/Techniques/failures/F2.html