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

Focus Management Tester

Practice and verify programmatic focus movement on delete, drawer open, and close.

Open tool

Continue Reading