Skip to content
BENIBIX Learn

Focus Trap

Design♿ AccessibilityKeyboard and Touch

Also known as Keyboard Trap, Focus Lock

The Tab key stays in one box, like a pop-up. It stays till you close it.

Think of it like

It is like a fenced garden. Inside a pop-up you stay in the fence until you use the gate.

Example

In a cookie dialog, Tab cycles through Accept and Settings. Escape closes it and focus returns to the page.

Why it matters

Done right, it stops people tabbing into a page they cannot see. Done wrong, it locks them in.

Definition

A focus trap keeps the keys inside one area. Tab loops around it instead of leaving. Inside an open modal dialog that is good, because the page behind is blocked. Escape or a Close button must always let people out. A trap with no way out, anywhere on a page, is a serious bug that WCAG level A forbids.

Common mistake

Trapping focus with no exit. Always let Escape or a Close button release it.

Key takeaways

  1. 1
    Wanted in a modal. Tab loops inside.
  2. 2
    Always an exit. Escape or Close.
  3. 3
    Return focus. Back to where it was.