Keyboard Trap Audit
A keyboard trap is part of a page that keyboard focus can move into but not out of. Someone using only a keyboard who tabs into it can’t reach the rest of the page. WCAG 2.1.2 No Keyboard Trap requires that focus can always be moved away using the keyboard. If that takes something other than the standard keys, users must be told how.
Experimental status
This audit is experimental while we validate it against more real-world sites. It runs on every scan. WCAG allows a non-standard way out as long as the page tells users about it, and the audit can’t read those instructions, so it never reports a confirmed failure. Its findings are always listed under Manual Checks Needed, and they don’t affect your accessibility score.
How the audit works
The audit presses Tab through the page and watches for focus cycling round a group of elements without reaching the rest. A modal dialog that keeps Tab inside itself is fine as long as Escape closes it, so focus cycling on its own is never reported.
When it finds a cycle, the audit tries the standard ways out, over several rounds, from each element in the cycle:
- Escape
- Shift+Tab
- The arrow keys
- Tab again
It only reports a trap when none of them frees focus. It never presses Enter or Space, because activating an unknown control could be destructive. It also avoids arrow keys on form fields and media players, where they would change a value.
Reading the results
The audit reports one of these outcomes:
- No cycle, or a cycle through every element on the page. Nothing was shut out. This is a pass.
- Escaped. Focus cycled within part of the page, and a standard key freed it. This is a pass.
- Trapped. Focus cycled within part of the page, and no standard key freed it. This is reported for review against the element that contains the cycle.
- Needs review for another reason. The audit couldn’t decide, but found something worth checking:
- Focus went into an iframe and never came back out.
- The only way out was past the edge of the page, and the page pulled focus straight back.
- The cycle had too many elements to try every key from every one of them.
To check a result, tab into the reported element and try to leave it with the keyboard. If the component tells users how to move focus away with another key, it may meet the criterion. You can then record your decision with the ignore feature.
Limitations
The audit stops at the first cycle it finds, so it reports at most one trap per page. It only sees the page as it loads. A trap inside a dialog or menu that opens later, for example after clicking a button, isn’t reached.
Some findings are not real traps:
- A dialog whose only way out is a button. A cookie consent dialog that keeps Tab inside itself and ignores Escape, but has a working close button, is reported because the audit never presses buttons.
- A long form inside an iframe. An embedded form with more than 256 fields looks the same as focus stuck in the frame.
- A large widget that lets focus out from the middle. In a cycle of more than 32 elements, the audit only tries the keys from the elements at each end.
- A component that documents its own way out. A code editor that keeps Tab for indenting and tells users another key to leave is still reported.
Pressing Escape during the check can close an overlay, so the audit reloads the page before the rest of the scan continues.
Related documentation
- Color-Only Focus AuditHow A11y Pulse detects focus indicators that rely on a change of text color alone, and when a color change is distinct enough to pass.
- Context Change on Focus AuditHow A11y Pulse detects unexpected context changes triggered merely by focusing an element.
- Focus Not Obscured AuditHow A11y Pulse detects focused elements that are completely hidden by sticky headers, footers, banners, and other overlays.
- Focus Order AuditHow A11y Pulse flags pages where keyboard focus repeatedly jumps a long way against the reading order, and why every result needs a human check.
- Skip Link AuditHow A11y Pulse checks that skip links actually move keyboard focus, and how to read the results.