Skip to main content
Perceivly: Perceivly home

2.1.2 No Keyboard Trap

Level A · added in WCAG 2.0

If you can move keyboard focus into a component, you must be able to move it out again with the keyboard alone. If leaving needs more than Tab, Shift+Tab, the arrow keys or another standard key, tell users how.

Who it helps

Keyboard and switch users have no way around a trap: they cannot click elsewhere, so the rest of the page becomes unusable. Screen reader users can be stuck in the same way.

How to meet it

Examples

Fails:A code editor that swallows every Tab press, with no way out
<textarea id="code"></textarea>
<script>
  document.getElementById("code").addEventListener("keydown", (e) => {
    if (e.key === "Tab") {
      e.preventDefault();
      insertAtCursor("\t");
    }
  });
</script>
Passes:Escape turns off Tab capture, and the instructions say so
<p id="code-help">Tab inserts a tab. Press Escape, then Tab, to leave the editor.</p>
<textarea id="code" aria-describedby="code-help"></textarea>
<script>
  const code = document.getElementById("code");
  let captureTab = true;
  code.addEventListener("focus", () => { captureTab = true; });
  code.addEventListener("keydown", (e) => {
    if (e.key === "Escape") captureTab = false;
    else if (e.key === "Tab" && captureTab) { e.preventDefault(); insertAtCursor("\t"); }
  });
</script>

Can a scanner detect this?

No

axe-core has no rule for keyboard traps, because finding one means pressing keys and watching where focus goes. Tab through the whole page and every widget, forward and backward, and confirm you can always leave.

No automated rule tests this criterion. Check it by hand.

Common mistakes

Official W3C explanation of 2.1.2

Check your own page

See which automated WCAG checks your page fails, with the failing elements and how to fix them.

Enter a page address, for example example.com/shop.

Reviewed November 2, 2026