0Pricing
Web Accessibility Academy · Lesson

Trapping Focus Inside the Modal

Keep Tab from escaping to the page behind.

Why Focus Must Stay In

While a modal is open, keyboard focus should stay inside it. If Tab escapes to the page behind, blind users get lost in content they cannot see.

The Native Element Helps

A real dialog opened with showModal() traps focus for you automatically, which is one big reason to prefer it over a div.

All lessons in this course

  1. Dialog Roles and the Native dialog Element
  2. Trapping Focus Inside the Modal
  3. Escape to Close and Restore Focus
  4. Inert Background and aria-modal
← Back to Web Accessibility Academy