We'd like to set Google Analytics cookies to learn how people use the Knowledge Base, so we can improve it. We set them only if you accept.

Skip to main content
Digital Accessibility Knowledge Base

missing-dialog-semantics

Web validation

Modal dialogs must have the proper semantics so that users know when the page context has changed.

A modal dialog changes the context of the page: users are asked to focus on the dialog before returning to the rest of the content. Sighted users see this change, because the dialog appears on top of the page. Users of assistive technology learn about it only when the dialog is exposed as a dialog in the accessibility tree. When a modal is built from generic elements, such as a plain <div>, without dialog semantics, screen reader users don't know that they have moved into a different part of the page. They may not realize a dialog has opened, what it is for, or that the content behind it is unavailable.

To give a modal the proper semantics, use a native <dialog> element or add role="dialog" to the modal's container. Both need additional attributes to work correctly:

  • A native <dialog> must be opened with showModal() to be modal, and it needs an accessible name, for example aria-labelledby pointing to its heading.
  • A custom role="dialog" needs aria-modal="true" and an accessible name.

Pass Patterns

Native <dialog> opened with showModal()

The native element exposes the dialog role, showModal() makes it modal, and aria-labelledby gives it a name.

HTML
<dialog id="delete-dialog" aria-labelledby="delete-title">
    <h2 id="delete-title">Delete file?</h2>
    <button>Cancel</button>
    <button>Delete</button>
</dialog>


<script>
    document.getElementById("delete-dialog").showModal();
</script>

Custom modal with role="dialog"

The container has role="dialog", aria-modal="true", and an accessible name from its heading.

HTML
<div role="dialog" aria-modal="true" aria-labelledby="delete-title">
    <h2 id="delete-title">Delete file?</h2>
    <button>Cancel</button>
    <button>Delete</button>
</div>

Fail Patterns

The modal looks like a dialog, but it has no dialog role, so assistive technology exposes it as ordinary page content.

HTML
<div class="modal">
    <h2>Delete file?</h2>
    <button>Cancel</button>
    <button>Delete</button>
</div>

WCAG techniques

Sufficient techniques

Try It Yourself

Using a screen reader

New to screen reader testing, or need a refresher?
Review this article first: Practical guides for using screen readers

  1. Load the page and open a screen reader.
  2. Open the modal dialog.
  3. Listen to what the screen reader announces.

Expected results: The screen reader announces a dialog and its name, for example “Delete file?, dialog”.

Actual results: The screen reader announces only the content inside the modal, with no indication that a dialog has opened.

Inspecting the browser dev-tools

  1. Open the modal dialog.
  2. In your browser's dev tools, select the modal's container and open the Accessibility panel.
  3. Check the container's role.

Expected results: The role is dialog, and the container has an accessible name.

Actual results: The role is generic, or the container has no dialog role at all.

FAQ

How does this issue relate to 4.1.2 Name, role, value?

SC 4.1.2 requires the role of user interface components to be programmatically determinable. A modal without dialog semantics does not expose its role, so assistive technology cannot tell users that the context has changed to a dialog.

Why is this issue marked as Serious?

Without dialog semantics, screen reader users may not realize a dialog has opened or that they have moved to a different part of the page. They can lose context and struggle to complete the dialog's task, so it is rated serious.

Is adding role="dialog" enough on its own?

No. A custom role="dialog" also needs aria-modal="true" and an accessible name, and it still needs keyboard focus management. A native <dialog> handles focus for you, but only when it is opened with showModal(), and it still needs an accessible name.

Standards and Regulations

StandardSuccess CriterionReference
WCAG 2.24.1.2 Name, Role, Value (A)For all user interface components, the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to assistive technologies.
EN 301 5499.4.1.2 Name, Role, ValueSame as the WCAG text.
Section 5081194.21(d)Sufficient information about a user interface element including the identity, operation and state of the element shall be available to assistive technology. When an image represents a program element, the information conveyed by the image must also be available in text.
508 Trusted Tester4.1.2-change-notify-links, 6.BThe page provides notification of each change in content that is the result of interaction with a link or button.

Personas impacted by this issue

Learn More