Focus Trap
Confining keyboard focus inside a modal surface so it cannot wander behind it.
A focus trap confines keyboard navigation to a modal region: tabbing past the last focusable element wraps to the first, and nothing outside can be reached until the surface closes. Without it, keyboard and screen-reader users tab straight out of a dialog and into content that is visually covered.
A correct trap does more than cycle tab. It must also hide the rest of the document from assistive technology, or the screen reader's virtual cursor wanders behind the modal even though tabbing cannot. Whether the rest is marked hidden from the accessibility tree or made genuinely inert matters: only the latter also blocks pointer events.
Stacked overlays are where traps get genuinely hard. When a second dismissable surface opens over a first, a single Escape reaches both handlers — the outer one, registered first, closes first, collapsing everything and stranding return focus on an element that no longer exists. The clean pattern is for the topmost surface to opt into claiming the event in the capture phase and mark it handled, with lower surfaces skipping anything already handled. Making capture the default breaks a different contract, where a child field legitimately swallows Escape before its container sees it.
Layering compounds this: a backdrop that does not establish a real layer leaves lower surfaces clickable, so focus escapes physically even when the trap is logically correct. See Stacking Context.
See also4
Focus Management
Deliberately controlling which element receives keyboard focus as an interface changes.
Design & Interface28 connections
Portal
Rendering an element into a different part of the document than its logical parent.
Web Platform18 connections
ARIA
Attributes that describe roles, states, and relationships to assistive technology when HTML cannot.
Design & Interface31 connections
Keyboard Navigation
Making every interactive affordance reachable and operable without a pointer.
Design & Interface34 connections
Related7
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from10
- ARIADesign & Interface
Attributes that describe roles, states, and relationships to assistive technology when HTML cannot.
- contenteditableWeb Platform
The HTML attribute that makes an element directly editable, and the surface behind most rich-text editors.
- Focus IndicatorDesign & Interface
The visible outline or highlight showing which element on a screen will receive keyboard input, essential for anyone who doesn't use a mouse, and for years routinely removed by designers who found it unattractive.
- Focus ManagementDesign & Interface
Deliberately controlling which element receives keyboard focus as an interface changes.
- Headless ComponentDesign & Interface
A component supplying behavior and accessibility with no styling of its own.
- Keyboard NavigationDesign & Interface
Making every interactive affordance reachable and operable without a pointer.
- Modal DialogDesign & Interface
A window that blocks the rest of the interface until it is dealt with, useful for decisions that truly demand attention and overused for almost everything else.
- PortalWeb Platform
Rendering an element into a different part of the document than its logical parent.
- Screen ReaderDesign & Interface
Software that turns an interface into speech or braille for people who can't see the screen, which navigates by structure rather than reading top to bottom, and exposes every shortcut a sighted design took.
- Stacking ContextDesign & Interface
The nested coordinate system that decides what paints above what, and why z-index often does nothing.