No Keyboard Trap
If focus can get into something, it has to be able to get out using the keyboard alone. A trap does not merely inconvenience a keyboard user — it ends their session, because there is nothing else they can do.
- Principle
- Operable
- Guideline
- 2.1
- Level
- A
- In WCAG since
- 2.0
- Number
- 2.1.2
Broken, then fixed
The same interface twice: first with the mistake, then with the smallest change that fixes it.
A hand-rolled focus trap with no way out.
The modal loops focus correctly but binds no Escape and its close button is mouse-only. A mouse user closes it without noticing; a keyboard user is finished.
The loop has an exit.
Trapping focus inside a modal is correct — the requirement is that the trap has a documented exit. Native <dialog> with showModal() provides one for free.
How to test
Check your own interface against 2.1.2, one step at a time.
- Start at the top of the page and press Tab repeatedly. Check that focus moves forward through every part of the page and on to the browser address bar.
- Press Shift+Tab from the end of the page. Check that focus moves back through every part of the page.
- Open each widget that takes focus, such as a dialog, a date picker, a video player, an embedded map or an iframe. Check that Tab, Shift+Tab or Escape moves focus out of it again.
- Where a widget needs some other key to leave, check that the page tells the person which key, before or inside the widget.
- Check content that loads later, such as a chat widget or an advert, the same way. A trap in a third-party embed fails the page it sits on.
Common questions
Is a modal dialog that keeps focus inside it a keyboard trap?
No, as long as the person can leave it. Holding focus inside an open dialog is expected; it passes when Escape, a close button or a cancel button returns focus to the page.
Do embedded players and third-party widgets count for 2.1.2?
Yes. Every part of the page has to let focus out, even content that you did not write and that does not help the page meet any other criterion. One trapped iframe stops a keyboard user from reaching anything after it.
Can a widget use an unusual key to let focus out?
Only when the page tells the person what that key is. Tab, Shift+Tab, the arrow keys and Escape need no explanation; anything else needs an instruction they can find before they get stuck.
Try it yourself
A lab is a small working piece of interface that you change yourself. Read its steps, use the controls under it, and watch the verdict line at the bottom: it says whether the criterion passes or fails as you go. Reset puts it back.
Try it: trap the focus, or let it go
How to use this lab
- Goal. Tab into a newsletter sign-up box, then back out to the rest of the page.
- The controls. The choices under “The widget” set it to “Trap focus, no way out”, “Trap focus, Escape lets it out” or “No trap: Tab moves on”. Press Tab and Press Escape move a drawn focus ring, and Take focus out of the widget always brings it back. Only the drawing is ever trapped: your own focus moves as usual.
- Try this. The lab starts with “Trap focus, no way out”, and fails. Press Tab a few times and watch focus loop between Email and Subscribe, then Press Escape. Then choose the other two settings and try again.
- What it means. If Tab moves on, or Escape lets focus out, 2.1.2 passes. If focus loops with no way out, 2.1.2 fails: people who use only a keyboard are stuck in the widget and can’t reach the rest of the page. The verdict line under the lab says which.
Only the drawing is ever trapped. Your own focus moves through this lab as usual.
2.1.2 fails
Also in guideline 2.1
Criteria in the same guideline often fail together.