Glossary

Keyboard trap

A keyboard trap is a component that keyboard focus can enter and cannot leave. For someone navigating by keyboard the page stops responding entirely: no amount of tabbing moves focus past the component, and the only remaining option is closing the tab and losing whatever was in progress. It is one of the most serious accessibility failures there is, and it is invisible to every automated check because it is a behaviour rather than a property of the markup.

How a trap is created

A modal dialog implementing focus containment without an escape route, so focus cycles inside forever.

An embedded third-party widget — a video player, a map, a payment frame — that captures keys and never returns focus.

A custom control handling the tab key itself and preventing the browser's default behaviour under a condition that is always true.

An event handler calling focus on an element every time focus leaves it, which is usually an attempt to validate a field.

In each case the code is doing something deliberate, and the trap is the case the author did not consider.

Why focus containment is not itself the problem

A modal dialog is supposed to contain focus: letting it wander behind the overlay is a different defect.

The requirement is that a standard way out exists — the escape key, a close control reachable in the cycle, or both.

So the distinction is between containment with an exit and containment without one, and only the second is a trap.

Which is also why the correct implementation is well documented: contain focus, handle escape, and return focus to the trigger on close.

Why no automated check finds one

Detecting a trap means entering the component, attempting to leave it, and observing that focus did not move — which requires interaction.

A static reading of markup shows the component and nothing about what its key handlers do.

Even a rendering check does not exercise it, because triggering the component usually requires an action nobody performed.

Which is why any tool reporting an accessibility pass is reporting the absence of detectable failures, not the absence of failures.

How to test for one

Put the mouse away and tab through the whole page from the top, including opening every dialog and interacting with every embedded widget.

In each component, tab until focus either leaves or cycles back to where it entered, and try the escape key.

A component that cycles without an exit and ignores escape is a trap.

It takes a few minutes per page and it finds what no scan can, which is the argument for doing it on the templates rather than on every page.

How it relates to what is observable

Elements made interactive without the semantics that make them reachable are detectable, and they are a common neighbour of trapping behaviour.

Positive tab index values are detectable and reorder the sequence globally, which makes a trap harder to reason about when one exists.

Interactive elements hidden from assistive technology while remaining focusable are detectable and produce a related confusion.

The trap itself is not among these, and the honest report says so rather than implying keyboard operation was verified.

Frequently asked questions

Is a modal dialog that contains focus a trap?
No — containment is correct for a modal. It becomes a trap when there is no way out: no escape key handling and no close control reachable in the focus cycle.
Can a scan tell me whether my site has one?
No. It requires interaction: entering a component and attempting to leave it. A clean accessibility result means no detectable failures, which is a narrower statement.
How do I find them?
Put the mouse away and tab through the page, opening every dialog and widget. A component that cycles forever and ignores escape is a trap. Minutes per template.

Sources

Related

VeriFixScan crawls a site and applies its checks to every page it reaches, keeping the evidence behind each finding. Scanning one website is free.

Scan a website