Keyboard focus must not get trapped

Keyboard users must be able to move focus into and out of every part of the page with standard keys. A widget that keeps Tab cycling inside it, or stops Tab entirely, locks them out of the rest of the page.

Readabler check

Rule IDrdb-keyboard-trap
ImpactCritical
Success criterion 2.1.2 No Keyboard Trap · A
StandardsWCAG 2.0 · WCAG 2.1 · WCAG 2.2 · Section 508 · EN 301 549
Readabler fix Needs a change in the website’s code

Example

Before
<div class="player" id="player">
  <button type="button">Play</button>
  <button type="button">Mute</button>
</div>
<script>
  player.onkeydown = (e) => { if (e.key === "Tab") { e.preventDefault(); nextControl().focus(); } };
</script>

Tab cycles Play, Mute, Play, Mute and never reaches the rest of the page.

After
<div class="player" id="player">
  <button type="button">Play</button>
  <button type="button">Mute</button>
</div>
<script>
  player.onkeydown = (e) => { if (e.key === "ArrowRight") { e.preventDefault(); nextControl().focus(); } };
</script>

Arrow keys move between the player controls. Tab leaves the player and continues down the page.

Why it matters

A keyboard trap is one of the most serious barriers on the web. Once focus is stuck, a keyboard-only user has no way to reach the rest of the page: no checkout button, no menu, no way out except reloading or closing the tab.

It affects everyone who cannot use a mouse: people with motor disabilities, switch and sip-and-puff users, and screen reader users who move with Tab. Typical sources are embedded video players, rich text editors, maps, date pickers and chat widgets, often third-party code.

WCAG 2.1.2 No Keyboard Trap is a Level A criterion with a special status: a trap anywhere on the page makes the whole page fail, even in content you do not claim conforms, because it stops the user from reaching everything else.

How to fix it

Do not take over the Tab key. Let Tab and Shift+Tab move in and out of your component. Use arrow keys for movement inside it, as toolbars, tab lists and menus do.

Modal dialogs are the exception. Keeping focus inside an open modal is expected, as long as the user can close it with Escape and a visible close button, and focus returns to where they were. The native element handles this for you:

<dialog id="size-guide">
  <h2>Size guide</h2>
  ...
  <button type="button" onclick="this.closest('dialog').close()">Close</button>
</dialog>
<script>
  document.getElementById("size-guide").showModal();
</script>

Editors that use Tab to indent text must offer a documented way out, such as pressing Escape and then Tab, and say so near the editor.

Third-party widgets. Update to the latest version, look for an accessibility setting, or replace the widget. If you cannot fix it, offer an alternative, for example a link to the video page.

Hidden content. Elements that are hidden off-screen but still focusable can make focus disappear: hide them with hidden or inert.

Checklist

  1. Never cancel the Tab key in your scripts.
  2. Let users close modal dialogs with Escape.
  3. Return focus after a dialog closes.
  4. Tab through every embedded widget and out again.

How the check works

The check presses Tab in a real browser, up to 150 times, and records each element that receives focus. It reports a trap when focus stays on the same element for three presses, or when focus starts looping through a small group that leaves at least three focusable elements and more than half of the page unreached. Loops inside an open dialog are not reported. Traps that start only after interaction, such as typing in an editor, need a manual check.

Resources

Updated October 27, 2026