Purpose
An alert dialog interrupts the user’s workflow to convey an urgent message that requires acknowledgment or a decision. Unlike a standard dialog, the alert dialog is announced immediately by screen readers.
Usage Guidance
Use alert dialogs for irreversible or high-stakes actions such as:
- Confirming data deletion
- Warning about session expiration
- Requiring agreement before proceeding
Do not use alert dialogs for informational messages that do not require a decision.
Accessibility Considerations
- Use
role="alertdialog"(notrole="dialog") so screen readers announce it immediately aria-modal="true"informs AT that content outside the dialog is inertaria-labelledbyassociates the visible heading with the dialogaria-describedbyassociates the body text with the dialog for context- Focus must be trapped within the dialog while open
- On close, return focus to the trigger that opened it
Keyboard Support
| Key | Action |
|---|---|
Tab |
Move focus forward among interactive elements within dialog |
Shift+Tab |
Move focus backward among interactive elements |
Escape |
Close the dialog (return focus to trigger) |
Enter / Space |
Activate focused button |
Screen Reader Behavior
Screen readers announce the dialog immediately upon opening, including the label and description. Focus is placed on the first focusable element or the dialog container itself.
ARIA Requirements
role="alertdialog"on the dialog containeraria-modal="true"on the dialog containeraria-labelledbypointing to the dialog’s headingaria-describedbypointing to the descriptive paragraph
Common Mistakes
- Using
role="dialog"instead ofrole="alertdialog"for urgent messages - Not trapping focus within the dialog
- Not returning focus to the trigger on close
- Closing the dialog automatically on a timer (always require user action)
Live Example
Delete Audit Record?
This action cannot be undone. The audit record and all associated testing evidence will be permanently deleted.
Code Example
<!-- Trigger -->
<button data-dialog-open="confirm-delete">Delete Record</button>
<!-- Alert Dialog -->
<div
id="confirm-delete"
role="alertdialog"
aria-modal="true"
aria-labelledby="confirm-title"
aria-describedby="confirm-desc"
hidden
>
<div class="dialog__inner">
<h2 id="confirm-title">Delete this record?</h2>
<p id="confirm-desc">This action cannot be undone.</p>
<div class="dialog__actions">
<button data-dialog-close>Cancel</button>
<button data-dialog-close>Confirm Delete</button>
</div>
</div>
</div>