Lab 1
Focus Lab
Focus indicator tester (WCAG 2.4.7 and 1.4.11)
Design a focus ring. Then watch it on twelve backgrounds at once. A ring that only works on white is a ring that fails for half the web.
Before you start
Press the Tab key right now. The outline that appears around the next link is the focus ring. For anyone who navigates by keyboard, switch, or voice, that ring is the cursor. Lose it and they are lost.
The lab below starts with this site's own ring: one blue outline, three pixels wide. It fails on eight of the twelve backgrounds. Your job is to make it pass on all twelve, then take the CSS with you.
The lab
Load a real ring from the presets, or design your own. Change a control and every cell updates. Each cell shows the sample button with your ring forced on, the background name, and the contrast ratio between your ring and that background. Tab into a cell to see the ring the way the browser would really draw it.
What you just learned
- One color can only match half the world. A dark ring vanishes on dark backgrounds, a light ring on light ones. The fix is two tones: one light, one dark, so one of them always has contrast.
- 3:1 is the floor, not the goal. WCAG 2.2 asks for 3:1 between a focus indicator and the colors next to it. Rings that clear 4:1 or 5:1 on every background are easier to spot in sunlight and at a glance.
- A gap helps. Offsetting the ring from the element edge keeps it from blending into borders and gives the eye a clean shape to find.
- Use
:focus-visible, not:focus. The generated CSS shows the ring for keyboard users and hides it after a mouse click, which is what each of those users expects. - Never
outline: nonewithout a replacement. The generated rule removes the default outline only when it puts a box-shadow ring in its place.
The presets
The preset buttons load rings that real systems ship. Scores are this lab's: the ring's two colors against the twelve backgrounds. The GOV.UK Design System's state is a yellow fill with a thick black bottom edge rather than a ring, so the lab scores its two colors, yellow and near-black, and they pass everywhere; the gallery entry shows the real shape. The two-tone default ring that current browsers draw also passes everywhere, which is a good argument for not removing it. The single-color outlines from large design systems score three or four of twelve, which is the point of the lab: one color cannot match every background, however good the color.
Read the companion note
The focus ring is the interface explains the five properties of a great ring and why most rings fail. Why your focus ring vanishes in dark mode covers the arithmetic behind the failing cells.
Why the busy pattern is in the grid
Buttons land on photos, charts, and striped tables. A ring has to survive there too. The busy cell checks your ring against every color in the pattern, because the ring can land on any of them.
Embed this lab
Host the Focus Lab on your own page with one element and one script. It runs entirely in the visitor's browser, sends nothing back, and adds a small credit link.
<div data-a11y-world-lab="focus"></div>
<script src="https://a11y.world/embed.js" async></script>
The lab's styles are scoped to its own container. If your page sets global styles on buttons or inputs, they apply inside the lab too, which is usually what you want.
Related notes
-
The focus ring is the interface
For anyone who moves through a page without a mouse, the focus ring is the cursor. Here is what a great one looks like and why most of them fail.
-
Why agents miss focus states
Static analysis cannot see a focus ring. Here is the three-step procedure an agent can run instead, and the one CSS pattern that passes everywhere.
-
Why your focus ring vanishes in dark mode
A ring designed on a white mockup is a coin toss once the page can be dark. The fix is not a darker ring. It is a second tone.
-
Tab order is a promise the DOM makes
The Tab key follows the HTML, not the layout. CSS cannot change that order, a positive tabindex hijacks it, and aria-hidden does not remove a stop. One real walk found 162 stops where a list of the markup said 64. Here is why, and how to check.
-
The sticky header that eats your focus
Shift+Tab back up a form and the field you land on slides under the sticky header. The browser scrolled just far enough, and just far enough is behind the bar. WCAG 2.2 calls it focus not obscured. One CSS property fixes it.
-
Where focus goes when a dialog opens
A dialog owes a keyboard user three things. Put focus inside it on open. Keep Tab inside while it is open. Give focus back to the opener on close. Miss any one and the reader is lost behind the dialog or dropped at the top of the page.
Proud of your ring?
Send the CSS and the score through the form. The best rings go in the gallery with credit.
Submit to the gallery