Lots of people never use a mouse. Some can't hold or aim one, because of a motor impairment, an injury or tremor. Some are blind and use a screen reader, which is driven from the keyboard. Others use switches, voice control or a mouth stick, and all of these act like a keyboard. Plenty of power users simply prefer it. On this page the mouse is "unplugged" inside every demo. Try each task using only the keyboard.
On a Mac: Tab may skip links and buttons until you turn on System Settings › Keyboard › Keyboard navigation. In Safari, also tick Settings › Advanced › "Press Tab to highlight each item on a webpage".
Task: turn on "Weekly digest" only, then press Save.
*:focus { outline: none; }, and the checkboxes are custom-styled,
so there is no sign of where you are. You have to count Tab presses and guess.
Designers often remove the outline because they don't like how it looks when people click.
Use :focus-visible instead: it only shows the ring for keyboard users.
WCAG 2.4.7 (Focus Visible, Level AA). WCAG 2.2 adds 2.4.13 (Focus Appearance, Level AAA) for how big and clear the ring should be.Task: search for "kettle". Count how many times you press Tab.
Task: fill in every field from top left to bottom right, pressing Tab to move to the next one, then submit.
flex-direction: row-reverse, order
and positive tabindex values. WCAG 2.4.3 (Focus Order, Level A) and 1.3.2 (Meaningful Sequence, Level A).Task: choose the Saturday morning delivery slot, turn on gift wrap, and press Pay now.
<div>s with click handlers. A <div> can't get
keyboard focus and doesn't respond to Enter or Space, so for a keyboard user this checkout simply
doesn't work. You can't buy anything. A real <select>, <input type="checkbox"> and
<button> get all of that for free. WCAG 2.1.1 (Keyboard, Level A).Task: type a title, add a line of code, then press Publish.
Task: open the Delete dialog, then change your mind and press Cancel.
<div> drawn on top of the page. Opening it doesn't move focus into it,
so Tab carries on through the buttons hidden behind the dark overlay, and you can't see where you are.
The dialog is at the end of the HTML, so you have to get through all of them first, Esc does nothing,
and the first button you reach is Delete. The native <dialog> element opened with showModal()
moves focus in, keeps it there, closes on Esc and returns focus afterwards. WCAG 2.4.3 (Focus Order, Level A)
and 2.4.11 (Focus Not Obscured (Minimum), Level AA).Here are demos 2, 4 and 6 again, rebuilt. Keep the mouse unplugged and Tab into the box below.
What changed, and what else you can do:
:focus-visible so it is clear and has good contrast.tabindex values.<button>, <a href>, <input> and <select>
are keyboard accessible already. If you must build a custom control, add tabindex="0", a role, and handlers for Enter, Space and the arrow keys.<dialog> with showModal(). Put the safe choice first.