Many people never touch a mouse: people who use a screen reader, people with a tremor or a broken wrist, and people who work faster with shortcuts. For them, the keyboard is the whole interface.
Focus order
Focus moves in the order people read: top to bottom, start to end of each line.
- In designs, number the Tab stops, so the build follows the same order.
- Keep the DOM order the same as the visual order. Do not fix the order with a positive
tabindex. - Start every page with a “Skip to content” link that jumps past the header and side navigation.
- Only things people can act on take focus. Use
tabindex="0"on a custom control or a scrollable region, never on text or headings. - A region that scrolls sideways, such as a wide table, takes focus so people can scroll it with the arrow keys. Give it a name with
aria-label.
The focus ring
Keyboard focus is always visible: a 2 px ring, 2 px away from the element.
| Part | Token | Value |
|---|---|---|
| Colour | color.border.focus |
Blue, at least 3:1 against the page in light and dark |
| Width | border.width.focused |
2 px |
| Gap | state.focus.offset |
2 px |
- Show the ring on
:focus-visible, so a mouse click does not draw it but the keyboard always does. - Never remove the outline without putting the same ring back.
- The ring is never yellow: the brand yellow is too light on white to be seen.
- A sticky header, drawer or toast must not cover the element that has focus. Leave room with
scroll-padding-top.
Moving focus
When something opens, focus goes into it. When it closes, focus goes back to what opened it.
| When | Focus goes to | When it closes |
|---|---|---|
| A dialog opens | The first field, or the dialog’s heading if it has no field | Back to the button that opened it |
| A drawer or menu opens | The first item | Back to the button that opened it |
| A toast appears | Stays where it is; the toast is announced | Nothing moves |
| An item is deleted from a list | The next item, or the list’s heading if it was the last | |
| A page loads after a form is sent | The page heading, or the first error |
- A dialog keeps focus inside it until it closes. Escape closes it.
- Never let focus fall back to the top of the page. If the element that had focus disappears, move focus to the nearest one that makes sense.
Keys for each kind of control
Beehexa components follow the WAI-ARIA Authoring Practices, the W3C guide to how each kind of control behaves with a keyboard and a screen reader. A group of controls, such as tabs or a menu, is one Tab stop; the arrow keys move inside it.
| Pattern | Keys | Pattern page |
|---|---|---|
| Button | Enter or Space activates | Button |
| Link | Enter follows | Link |
| Checkbox, switch | Space toggles | Checkbox, Switch |
| Radio group | Arrow keys move and select; Tab leaves the group | Radio group |
| Tabs | Left and Right move between tabs; Home and End jump to the first and last | Tabs |
| Menu | Up and Down move; Enter chooses; Escape closes | Menu button |
| Select, combobox | Up and Down move through options; Enter chooses; Escape closes the list, then clears | Combobox |
| Dialog | Tab cycles inside; Escape closes | Dialog |
| Disclosure, accordion | Enter or Space opens and closes | Disclosure, Accordion |
| Data table | Tab reaches the controls inside rows; a sortable header is a button | Table |
Each component’s Accessibility tab, such as Button, lists its exact keys and any difference from its pattern.
Shortcuts
- Every shortcut has another way to do the same thing, such as a button or a menu item.
- Use Ctrl or ⌘ with a letter. A single-letter shortcut must be possible to turn off or remap (WCAG 2.1.4).
- Do not take over keys that browsers and screen readers use, such as Ctrl F or the arrow keys outside a widget.
- Show shortcuts in tooltips and menus, so people learn them.