Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,199 of 9,199 pages
About the help in other languages
All help pages

Keyboard and focus

Making every control of a design usable with a keyboard: a visible focus ring with :focus-visible, a logical tab order, real buttons and links, menus and dialogs that manage focus, and admin4's focus rules as an example.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/theme-design/keyboard-and-focus.md

On this page

Keyboard and focus

This page is for designers and front-end developers of a design. Many people use a keyboard instead of a mouse. The page answers: how focus must look, how it must move, and which elements to use.

Contents

  1. A visible focus ring
  2. Real elements
  3. Tab order
  4. Menus, disclosures and dialogs
  5. Testing with the keyboard

A visible focus ring

Every element that can receive focus must show it. admin4's rule (components.css):

The theme switch of the header with the keyboard focus ring around it
The theme switch of the header with the keyboard focus ring around it
.a4-page :focus-visible,
.a4-focus:focus-visible,
.a4-btn:focus-visible {
  outline: 3px solid var(--a4-ring);
  outline-offset: 2px;
}
  • :focus-visible shows the ring for keyboard focus and not after a mouse click.
  • The ring color is a token with 3:1 contrast against the page in both themes.
  • Never write outline: none unless the same rule draws another clear indicator.

For a public design:

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--site-focus);
  outline-offset: 2px;
}

Real elements

  • A thing that goes somewhere is an <a href>; a thing that does something is a <button type="button">.
  • Do not make a <div> clickable: it is not focusable and does not react to Enter and Space.
  • <details> and <summary> give a working disclosure without script.

Tab order

  • Follow the visual order in the source order; do not fix it with positive tabindex values.
  • tabindex="-1" only for elements you focus by script (a dialog, the target of a skip link).
  • Hidden content (closed menus, off-canvas panels) must be out of the tab order: hidden, display: none or inert.
WidgetKeyboard behavior
Menu buttonEnter/Space toggles; aria-expanded says the state; Escape closes and returns focus to the button
Off-canvas navigationfocus moves into it when opened, Tab stays inside while open, Escape closes
Dialogprefer <dialog> with showModal(); focus goes in, Escape closes, focus returns to the opener

admin4's side drawers follow this model (focus to the first control, focus trap, Escape returns focus to the tab, aria-expanded on the tab), as described in the admin styling guide.

Testing with the keyboard

  1. Click into the address bar, then press Tab repeatedly through the whole page.
  2. Is the first stop the skip link? Is focus always visible? Does the order make sense?
  3. Open every menu and dialog with the keyboard, and close it with Escape.
  4. Repeat at 200% zoom and in dark mode.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x