EvenScout Free scan

Guides

How to find and fix keyboard traps

A keyboard trap stops people who do not use a mouse from leaving part of your page. It is one of the few problems that can block a purchase completely. Updated 27 November 2026.

What a keyboard trap is

WCAG success criterion 2.1.2, "No keyboard trap" (level A), says: if keyboard focus can move into a component, it must be able to move out again using the keyboard. If that needs more than the Tab, Shift+Tab or arrow keys, the user must be told how.

Traps affect people who navigate by keyboard, screen-reader users and people using switch devices. For them, a trap means the rest of the page simply stops existing.

A five-minute test

  1. Put the mouse aside and click into the browser's address bar, then press Tab to enter the page.
  2. Keep pressing Tab. Focus should move forward through every link, button and field, and you should always see where it is.
  3. Press Shift+Tab to go back. It should retrace the same path.
  4. Open each pop-up, menu, date picker, video player, map and chat widget, then try to leave it with Tab, Shift+Tab and Escape.
  5. If focus ever stays on the same element, or loops inside a widget you cannot close, you have found a trap.

Common causes

  • A script that cancels the Tab key, often added to "help" a field such as a promo code or a search box.
  • Embedded third-party widgets in iframes: chat, video, maps or payment forms that capture focus.
  • Custom pop-ups that keep focus inside but offer no keyboard way to close.
  • Rich text editors and code fields that use Tab for indenting without telling the user how to leave.

How to fix them

  • Do not cancel the Tab key. Remove handlers like the one below.
  • Give every pop-up a keyboard way out: a close button that can be reached by Tab, and the Escape key. When it closes, send focus back to the control that opened it.
  • Choose embeds that have been tested with the keyboard, or provide a link around them.
  • If a component needs special keys to exit, say so on screen, next to it.

A trap in practice, in JavaScript:

// Traps keyboard users in the promo code field. Remove this.
promo.addEventListener('keydown', function (e) {
  if (e.key === 'Tab') { e.preventDefault(); }
});

Not every focus loop is a trap

A modal dialog that keeps focus inside it while it is open is good practice, not a failure, as long as the user can close it with the keyboard and focus then returns to the page. The test is simple: can you always get out?

Let an agent do the Tab test for you

EvenScout's agents press Tab through your pages, open widgets and note exactly where focus gets stuck. See a real example in our sample report.

Request a free scan