Keyboard & Focus6 min readUpdated 2026-11-15
Accessible Modal Dialogs: Focus Trap, Escape & Focus Restoration
Prevent focus leaks and traps with native <dialog>.showModal() or WAI-ARIA modal focus management.
Key Takeaways
- Move focus inside the dialog upon opening.
- Keep Tab and Shift+Tab inside the open modal (inert background).
- Always close on Escape and return focus to the trigger button.
Preferring Native <dialog>
Calling dialog.showModal() automatically traps focus inside the modal, enables Escape dismissal, and makes the background page inert.
Frequently Asked Questions
No—only modal dialogs that block background interaction should trap Tab focus.
Interactive Tools for This Guide
ARIA & Dev
Accessible Modal Generator
Generate accessible <dialog> / ARIA modals with Escape key and focus return.
Open tool
Keyboard & Focus
Modal Keyboard Testing Guide
Verify modal initial focus, Tab wrap, Escape close, and trigger focus return.
Open tool
ARIA & Dev
Focus Management Tester
Practice and verify programmatic focus movement on delete, drawer open, and close.
Open tool