How to Make a Modal Dialog Accessible
An accessible modal dialog moves keyboard focus inside when it opens, keeps Tab and Shift+Tab cycling within it, closes with Escape, and returns focus to the control that opened it. It needs role dialog, aria-modal set to true, and an accessible name, and the page behind it must be inert.
ADASupport · Published and sources checked December 1, 2026

What makes a modal dialog accessible?
W3C's ARIA Authoring Practices Guide (APG) defines a dialog as a window overlaid on the primary window or on another dialog. In a modal dialog, the windows underneath are inert: people cannot interact with content outside the dialog until it closes, and that content is usually dimmed or obscured. A modal dialog keeps its own tab sequence, so Tab and Shift+Tab never move focus out of it, and unlike most non-modal dialogs there is no way to move focus outside without closing it.
That gives four things to get right: where focus lands when the dialog opens, how the keyboard behaves inside it, where focus goes when it closes, and the roles and properties that tell assistive technology what it is. Each maps to WCAG success criteria that already apply to the rest of your site, including 2.1.2 No Keyboard Trap and 2.4.3 Focus Order, both Level A.
Source: W3C WAI, Dialog (Modal) Pattern. For the wider basics, see our guides to keyboard access and focus order.
Where should focus go when a modal dialog opens?
When a dialog opens, focus moves to an element inside it. APG says this is generally the first focusable element, but the right choice depends on the dialog's content and size. If the dialog holds content people need to read first, such as a list, a table or several paragraphs, put focus on a static element at the start (given tabindex="-1") so screen reader users hear it from the top. Do the same when focusing the first control would scroll the beginning of a long dialog out of view.
For a final step that is hard to reverse, such as deleting data or completing a financial transaction, APG says it may be advisable to focus the least destructive action, like Cancel. For dialogs that only give information or continue a process, focus the most frequently used control, such as an OK or Continue button.
Which keys should work inside a modal dialog?
APG's keyboard model is short. Tab moves to the next tabbable element in the dialog and wraps from the last one back to the first. Shift+Tab moves backward and wraps from the first to the last. Escape closes the dialog. APG also strongly recommends a visible button that closes the dialog, such as a close icon or a Cancel button, so mouse, touch and voice users have an obvious way out too.
Keeping focus inside a modal is not a keyboard trap. W3C's Understanding document for SC 2.1.2 No Keyboard Trap says restricting focus inside a modal dialog does not fail the criterion as long as the user knows how to leave it, and it names Escape as a common standard exit. Its own example is a modal whose focus cycles from the last control to the first and which closes with Cancel, OK or Escape. A dialog with no working Escape and no reachable close button is where the trap problem starts.
Read W3C’s Understanding SC 2.1.2 No Keyboard Trap.
Where should focus go when a modal dialog closes?
APG says focus returns to the element that opened the dialog. There are two exceptions: if that element no longer exists, send focus to another element that keeps a logical workflow, and if the task makes a different element more useful, go there instead. APG's example is an Add Rows dialog that, once closed, puts focus on the first cell of the first new row.
W3C's Understanding document for SC 2.4.3 Focus Order describes the same flow: when the trigger is activated the dialog opens and focus is set inside it, content outside becomes inert and cannot receive focus, and on dismissal focus returns to the button or the element after it. If focus jumps to the top of the page instead, keyboard and screen reader users lose their place. WCAG lists the HTML dialog element as a sufficient technique (H102) for creating modal dialogs.
Read W3C’s Understanding SC 2.4.3 Focus Order. State and local government sites must meet WCAG 2.1 Level AA under the ADA Title II rule, which includes this criterion; see our Title II web rule overview.
Which ARIA attributes does a modal dialog need?
APG lists the roles and properties: the container has role dialog, every element needed to operate the dialog is inside that container, aria-modal is set to true, and the dialog has an accessible name, either aria-labelledby pointing to its visible title or aria-label. aria-describedby is optional and suits a short description; leave it off when the content is a list, a table or several paragraphs.
Only mark a dialog modal when it really is. APG warns that aria-modal can stop some assistive technology users from perceiving content outside the dialog, so use it only when your code prevents all users from interacting with outside content and the styling visibly obscures that content. aria-modal replaces the older practice of putting aria-hidden="true" on the background; if you still use that method, the dialog itself must not sit inside any element with aria-hidden="true".
Our guide to ARIA labels covers accessible names in more detail.
When should you use an alert dialog instead?
APG defines an alert dialog as a modal dialog that interrupts the user's workflow to communicate an important message and get a response, such as an action confirmation or an error that must be acknowledged. It uses role alertdialog, which lets browsers and assistive technology treat it differently, for example by playing a system alert sound.
An alert dialog follows the modal dialog keyboard rules and also needs aria-modal set to true and an accessible name. The extra requirement is that aria-describedby must point to the alert message, so it is read when the dialog appears. Do not use one for routine confirmations such as an item added to a cart; a status message is usually the better pattern there.
Source: W3C WAI, Alert and Message Dialogs Pattern. For non-blocking updates, see accessible cart confirmations and status messages.
How do you test a modal dialog for accessibility?
Use only the keyboard. Open the dialog and check that focus lands inside it in a sensible place. Press Tab and Shift+Tab past the last and first controls and confirm focus wraps without reaching the page behind. Press Escape and confirm the dialog closes and focus returns to the trigger. Then repeat with a screen reader and check that the dialog's name is announced when it opens and that you cannot browse into the background while it is open.
Also check focus visibility. WCAG 2.2's Understanding document for SC 2.4.11 Focus Not Obscured (Minimum), Level AA, says a properly built modal will always pass because it takes focus when it appears and holds it until dismissed. An overlay that neither takes focus nor limits interaction, and does not close when focus leaves it, is at risk of failing because it can cover the focused item.
Read W3C’s Understanding SC 2.4.11 Focus Not Obscured (Minimum) and our guide to focus not obscured.
This guide is educational and does not establish website conformance or provide legal advice.
Frequently asked questions
What makes a modal dialog accessible?
It moves focus inside when it opens, keeps Tab and Shift+Tab cycling within it, closes with Escape and a visible close button, returns focus to the trigger on close, and uses role dialog, aria-modal and an accessible name, with the background made inert.
Is trapping focus in a modal dialog a WCAG failure?
No. W3C's Understanding document for SC 2.1.2 No Keyboard Trap says restricting focus inside a modal does not fail the criterion as long as users know how to leave it, for example with Escape or a Cancel or close button.
Where should focus go when a modal dialog opens?
Usually the first focusable element. For content people must read first, focus a static element at the start. For destructive final steps, consider the least destructive action, such as Cancel.
Where should focus go when a modal dialog closes?
Back to the element that opened it, unless that element is gone or the workflow makes another element more logical, such as the first new row after an Add Rows dialog.
Do I need aria-modal on a dialog?
Use aria-modal="true" on a dialog that is truly modal: your code blocks interaction with outside content and the styling visibly obscures it. W3C warns it can hide outside content from some assistive technology users, so do not use it on non-modal dialogs.
What is the difference between a dialog and an alert dialog?
An alert dialog is a modal dialog that interrupts the user to deliver an important message and get a response. It uses role alertdialog and needs aria-describedby pointing to the message.