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
A visible focus ring
Every element that can receive focus must show it. admin4's rule (components.css):

.a4-page :focus-visible,
.a4-focus:focus-visible,
.a4-btn:focus-visible {
outline: 3px solid var(--a4-ring);
outline-offset: 2px;
}:focus-visibleshows 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: noneunless 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
tabindexvalues. 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: noneorinert.
Menus, disclosures and dialogs
| Widget | Keyboard behavior |
|---|---|
| Menu button | Enter/Space toggles; aria-expanded says the state; Escape closes and returns focus to the button |
| Off-canvas navigation | focus moves into it when opened, Tab stays inside while open, Escape closes |
| Dialog | prefer <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
- Click into the address bar, then press Tab repeatedly through the whole page.
- Is the first stop the skip link? Is focus always visible? Does the order make sense?
- Open every menu and dialog with the keyboard, and close it with Escape.
- Repeat at 200% zoom and in dark mode.
Related pages
- Skip links
- Accessibility basics for themes
- Reduced motion
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
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.