Loading...
Focus trapping, keyboard controls, and proper announcements
Modal dialogs interrupt the user's workflow. The key ARIA attributes are role='dialog', aria-modal='true', and aria-labelledby to connect the dialog to its title.
Tells screen readers this is a dialog requiring user attention before returning to the main content.
Indicates the dialog is modal—content behind it is inert and shouldn't be accessible.
Points to the dialog's title element. Users hear "Dialog: [title]" when it opens.
Click the button to open an accessible modal. Try pressing Escape, clicking outside, or using Tab.
<!-- ❌ INACCESSIBLE -->
<div class="modal">
<div class="modal-content">
<span onclick="close()">×</span>
<h2>My Modal</h2>
</div>
</div><!-- ✅ ACCESSIBLE -->
<div role="dialog"
aria-modal="true"
aria-labelledby="dialog-title">
<h2 id="dialog-title">Confirm</h2>
<button aria-label="Close">×</button>
</div><dialog> element with showModal() provides focus trapping and Escape handling automatically.