Sub topic 9
Making focus visible
Keyboard users need to see where they are on the page. The focus indicator is the visual mark that shows which element will receive the next key press. This chapter covers what WCAG requires, how to specify indicators in a wireframe, and the failures that usually show up later in development. It assumes you know how Tab order works from the earlier chapters on reading order and keyboard interaction, and that you have read the contrast chapter.
Why focus visibility matters
People who use a keyboard, a switch device, voice control that sends key events, or a screen magnifier all depend on the focus indicator. Without it, they press Tab and have no idea what changed. They may activate the wrong control or give up.
Browsers draw a default indicator, so the problem is almost always self-inflicted. A designer or developer removes the default outline because it looks untidy, then never replaces it. The wireframe is where you prevent this. If no focus state is drawn, no one decides what it looks like, and the default gets removed under deadline pressure.
What WCAG asks for
Several success criteria apply to focus. They differ in level and in the WCAG version that introduced them.
| Criterion | Level | What it requires |
|---|---|---|
| 2.4.7 Focus Visible | AA | Any keyboard-operable interface has a mode where the focus indicator is visible. |
| 1.4.11 Non-text Contrast | AA | UI components and their states need at least 3:1 contrast against adjacent colors. This covers the focus indicator. |
| 2.4.11 Focus Not Obscured (Minimum) | AA (WCAG 2.2) | A focused element is not entirely hidden by author-created content such as sticky headers or cookie banners. |
| 2.4.12 Focus Not Obscured (Enhanced) | AAA (WCAG 2.2) | No part of the focused element is hidden. |
| 2.4.13 Focus Appearance | AAA (WCAG 2.2) | The indicator is at least 2 CSS pixels thick around the element and changes by at least 3:1 between focused and unfocused states. |
Most teams target AA. Treat the AAA focus appearance rule as a good design target anyway, because it describes an indicator that works in practice. A 2 px or thicker line with strong contrast is easy to specify in a wireframe and cheap to build.
Specifying the indicator in the wireframe
A wireframe is usually grey boxes, so you do not need final colors. You do need to commit to three things:
- Shape. Say whether the indicator is an outline around the element, a thick underline, or a change of background. An outline works for nearly every component type.
- Thickness and gap. Write a number, for example "3 px, 2 px gap". A thin 1 px dotted line is easy to miss, especially for people with low vision.
- Consistency. Define one indicator for the whole product, then list the exceptions. A single shared style is easier to test and easier for users to learn.
For each interactive component in your component library sketch, draw a focused variant next to the default one. Include links, buttons, inputs, checkboxes, radio buttons, tabs, menu items, custom controls and table rows that can be selected.
Annotation example
Here is how a focus annotation might read for a checkout page.
| Component | Focus indicator | Notes |
|---|---|---|
| Text link | 3 px outline, 2 px offset | Indicator wraps the whole link text, including wrapped lines. |
| Primary button | 3 px outline, 2 px offset | Contrast against the page background is at least 3:1. |
| Text input | 3 px outline, 2 px offset | Border color may also change, but the outline is the required signal. |
| Card that acts as a link | Outline around the whole card | Only one tab stop per card. |
| Sticky header | None | Page content must scroll clear of it, with at least 80 px of scroll padding. |
The CSS the annotation turns into
The developer's implementation should look much like the following. This is the baseline from the spine example.
:focus-visible {
outline: 3px solid #005fcc;
outline-offset: 2px;
}
button,
[role="button"] {
min-width: 24px;
min-height: 24px;
}The color #005fcc has a contrast ratio of about 6:1 against white, which clears the 3:1 threshold. Check your own pair with the contrast function from the contrast chapter.
:focus versus :focus-visible
:focus matches whenever an element has focus, including after a mouse click. That is why many designers dislike it: a button shows a ring after every click. :focus-visible matches only when the browser decides the user needs to see focus. That is usually keyboard navigation, and always for text inputs. Using :focus-visible gives keyboard users a clear ring without showing it to mouse users on buttons.
Never write outline: none or outline: 0 unless you replace it with another visible indicator in the same rule. A reviewer should flag any such rule.
Indicators that work on any background
A single-color outline fails when the page background changes. A blue ring is clear on white but weak on a dark navy banner. A two-tone indicator solves this with a dark ring and a light ring, so one of them always contrasts with whatever sits behind it.
:focus-visible {
outline: 2px solid #ffffff;
outline-offset: 2px;
box-shadow: 0 0 0 2px #000000;
}The black shadow fills the 2 px gap between the element and the white outline. The result is a ring that reads on light, dark and image backgrounds. In the wireframe, annotate this as "two-tone ring" for any component that can appear over varied backgrounds, such as buttons on a hero image.
Forced colors mode
Windows High Contrast and other forced colors modes replace author colors with system colors. They keep outline but remove box-shadow. So an indicator built only from box-shadow disappears in these modes. In the example above, the white outline remains. Prefer outline as the main indicator, and treat shadows as decoration on top.
Focus must not be hidden
WCAG 2.2 added a rule about covered focus. A sticky header, a chat widget or a cookie banner can sit on top of the element that just received focus. The user tabs down the page and the focus ring slides under the header, out of sight.
In the wireframe, mark every element that stays fixed on screen: headers, footers, floating buttons, banners. Then note that content must not be covered when focused. Developers can handle the common case with scroll padding.
html {
scroll-padding-top: 5rem;
scroll-padding-bottom: 4rem;
}The browser then scrolls a focused element so it ends up clear of the fixed regions. Set the values to at least the height of the fixed header and footer.
A modal dialog or a dismissible banner that covers part of the page is a related case. When it opens, focus should move into it. When it closes, focus should return to the element that opened it.
Decision flow for each component
The diagram shows how to decide on the indicator for a component while you annotate.
Common errors
- Removing the outline for looks. The most frequent failure of 2.4.7. Fix it by replacing the outline, not by deleting it.
- Indicator only inside the element. An inset glow on a small button is hard to see. Use an outline outside the border box.
- Low contrast ring. A light grey ring on white fails the 3:1 requirement.
- Clipped outline. A parent with
overflow: hiddencuts off an outline drawn outside a child. Leave space in the layout, or draw the ring inside. - Color change as the only signal. A link turning from blue to slightly darker blue is not a focus indicator. Add a shape change.
- Custom components with no focus state. A div with a click handler gets no default ring. Specify one, and make sure it can receive focus at all.
Exercises
Exercise
A developer proposes button:focus { outline: none; background: #e8e8e8; } on a white page. Name two reasons this is likely to fail the focus criteria, and describe a better specification.
Show answer
A light grey background change on white has far less than 3:1 contrast, so it fails the non-text contrast requirement. Also, a fill change alone is subtle and gives no clear shape around the button, so many users will not notice it. Better: keep an outline, for example button:focus-visible { outline: 3px solid #005fcc; outline-offset: 2px; }, and the background change can stay as an extra cue.
Exercise
Your wireframe has a sticky 72 px header. Explain what can go wrong for a keyboard user and what you would annotate to prevent it.
Show answer
When the user tabs down the page, the browser may leave the focused element behind the header, so the focus ring is hidden. This fails Focus Not Obscured (Minimum). Annotate that focused content must stay visible below the header, and ask developers to set scroll-padding-top to at least the header height, for example 5rem.