R

RatedWithAI

WCAG guidance

Scan your site

WCAG 2.1

2.1.2 No Keyboard Trap

Level A success criterion

Users must be able to navigate away from any component using only the keyboard.

Why it matters

Keyboard users can become trapped in components with no way to escape, forcing a browser restart or abandonment.

Common violations

  • Modal dialogs with no close mechanism via keyboard
  • Embedded media players that capture all key events
  • Custom widgets that don't release focus
  • Infinite tab loops within components

Code examples

Bad

<div tabindex="0" onkeydown="event.preventDefault()">Trapped content</div>

Good

<dialog>
  <button onclick="this.closest('dialog').close()">Close</button>
  Content here
</dialog>

How to fix

Ensure all interactive components allow users to exit via Tab, Escape, or arrow keys. Document non-standard exit methods if used.

Related criteria

Related resources

Scan your site

Check your WCAG coverage in minutes

Start a free scan