View the source code for this site on GitHub Skip to main content

Keyboard Navigation

Currently focused element: None

WCAG 2.1.2 No Keyboard Trap (Level A)

This page demonstrates how to handle keyboard focus properly and avoid keyboard traps.

Accessible Modal Example

This modal demonstrates proper keyboard handling:

Bad Example (For Demonstration Only)

This example shows a problematic implementation that creates a keyboard trap:

Custom Widget with Proper Keyboard Support

Interactive Widget

Best Practices for Avoiding Keyboard Traps

  • Always provide a way to exit modals using the keyboard (ESC key)
  • Ensure all interactive elements can be reached using Tab key
  • Return focus to the triggering element when closing dialogs
  • Maintain a logical tab order that matches visual layout
  • Test your interface using only a keyboard
Press Tab to navigate, ESC to close modals