Focus Trap
Keeping keyboard focus inside a dialog until it closes.
See it on the 3D treeGoing deeper
While a modal dialog is open, tabbing cycles within it instead of reaching the page behind. Focus moves into it on opening, Escape or a close button dismisses it, and focus usually returns to the control that opened it. A trap with no keyboard exit is an accessibility failure.
Why it matters
It keeps keyboard focus off the page behind while still letting people leave; screen readers also need that page made inert.
In practice
A confirmation dialog opens with focus on its safe option, and tabbing moves only between its buttons.
Common mistake
Trapping focus but forgetting to return it afterwards, leaving users at the top of the page.
Connected terms
- Focus OrderEntry, cycling and return are all part of a planned sequence.
- Keyboard NavigationThe trap changes where keyboard movement can go until the dialog closes.
- ModalModal dialogs are the main case where containing focus is appropriate.