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
Hand-picked in the note itself — the neighbours worth reading next.
Focus Management
Deliberately controlling which element receives keyboard focus as an interface changes.
Design & Interface14 connections
Portal
Rendering an element into a different part of the document than its logical parent.
Web Platform14 connections
ARIA
Attributes that describe roles, states, and relationships to assistive technology when HTML cannot.
Design & Interface10 connections
Keyboard Navigation
Making every interactive affordance reachable and operable without a pointer.
Design & Interface12 connections
Related4
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from7
Notes elsewhere in the wiki that reach for this one.
- 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 ManagementDesign & Interface
Deliberately controlling which element receives keyboard focus as an interface changes.
- Headless ComponentDesign & Interface
A component supplying behaviour and accessibility with no styling of its own.
- Keyboard NavigationDesign & Interface
Making every interactive affordance reachable and operable without a pointer.
- PortalWeb Platform
Rendering an element into a different part of the document than its logical parent.
- Stacking ContextDesign & Interface
The nested coordinate system that decides what paints above what, and why z-index often does nothing.