Focus Visible
Keyboard focus has to be visible. Removing the outline because it is ugly is the single most common accessibility failure on the web, and it makes a site unusable rather than merely awkward.
- Principle
- Operable
- Guideline
- 2.4
- Level
- AA
- In WCAG since
- 2.0
- Number
- 2.4.7
Broken, then fixed
The same interface twice: first with the mistake, then with the smallest change that fixes it.
The outline was removed and nothing replaced it.
outline: none with no substitute. Focus is somewhere; the reader cannot see where. Tabbing becomes guesswork and typing goes into a field they cannot identify.
A ring with its own contrast and an offset.
Restyling the ring is fine; removing it is not. Give it 3:1 against its surroundings and an outline-offset so it does not disappear into a dark control — and use :focus-visible so it appears for keyboards without following every mouse click.
What changed in the code
The fix as a diff: removed lines are marked with a minus, added lines with a plus.
removed: button:focus { outline: none; }
added: button:focus-visible {
added: outline: 3px solid var(--focus);
added: outline-offset: 2px;
added: }
The CSS rule this page uses on every interactive element, verbatim.
Watch it happen
These demos play the failure out over time. They are silent and captioned, and you can pause or scrub at any point.
Tab order not started
Tab order not started — invisible
How to test
Check your own interface against 2.4.7, one step at a time.
- Click in the address bar and press Tab through the whole page. At each stop, check that you can see which element has focus without moving the mouse.
- Note any element where focus seems to vanish: nothing changes on screen, or the only change is too faint to spot.
- Repeat inside every menu, dialog, tab set and custom widget, using the arrow keys where the widget expects them.
- Search the stylesheets for outline: none, outline: 0 and styles on :focus. Check that each one that removes the browser outline puts a visible style in its place.
- Repeat the Tab pass in dark mode and with a Windows contrast theme turned on, where a focus style made only of a background colour or a shadow can disappear.
Common questions
Does the browser’s default focus outline pass 2.4.7?
Yes, in most cases, as long as nothing on the page removes it or hides it. Check it against your own colours, though: a default outline can be hard to see on some backgrounds.
Does 2.4.7 set a minimum size or contrast for the focus indicator?
No. 2.4.7 asks only that the indicator is visible. 1.4.11 Non-text Contrast asks that it stands out from its background, and 2.4.13 Focus Appearance, at Level AAA, sets its size.
Can I show the focus ring only to keyboard users with :focus-visible?
Yes. 2.4.7 asks for a visible indicator when the page is used from the keyboard, and :focus-visible gives exactly that while hiding the ring after a mouse click.
Try it yourself
A lab is a small working piece of interface that you change yourself. Read its steps, use the controls under it, and watch the verdict line at the bottom: it says whether the criterion passes or fails as you go. Reset puts it back.
Try it: style your own focus ring
How to use this lab
- Goal. Style a focus ring on a dark Save button so it can still be seen.
- The controls. The Ring thickness slider sets how thick the ring is, from none to 6px. The Gap from the button slider sets the space between the button and the ring, from touching to 6px. The options under “Ring colour” pick Blue, Black, Mid grey or Yellow, and the results give the ring’s contrast against each colour it touches.
- Try this. The lab starts with a blue ring 2px clear of the button. Drag Gap from the button to touching, then try Black and Yellow. Then drag Ring thickness to none.
- What it means. 2.4.7 passes when the ring reaches 3 : 1 against everything it touches: the white page and, with no gap, the dark button too. It fails when the ring is lost against either, or there is no ring, because keyboard users can’t see where they are. The verdict line under the lab says which.
- 6.70:1 against the pageStands out: needs 3:1 (AA · 1.4.11)
2.4.7 passes
Also in guideline 2.4
Criteria in the same guideline often fail together.
- 2.4.1, OperableLevel A
Bypass Blocks
Fails when: Every menu link stands between the reader and the article.
- 2.4.2, OperableLevel A
Page Titled
Fails when: The same title on every page.
- 2.4.3, OperableLevel A
Focus Order
Fails when: A dialog opens and focus stays behind it.
- 2.4.4, OperableLevel A
Link Purpose (In Context)
Fails when: Three “read more” links, with their titles in a separate column.
- 2.4.5, OperableLevel AA
Multiple Ways
Fails when: A deep hierarchy and nothing else.
- 2.4.6, OperableLevel AA
Headings and Labels
Fails when: Headings that describe nothing.