Search topics
Focus states shown only by a change of colour
The outline is removed and focus only turns a link's text blue, or gives it a pale fill, the same as hover: too close to the colour it had to stand out.
a:focus { color: #1a4fd0; outline: none; } The problem
People who can't tell the two colours apart can't find which link keyboard focus is on
A shop's account page has a list of links down its side: Orders, Saved items, Addresses and Payment methods. The design is quiet on purpose. The links are a dark grey, and on hover the one under the pointer turns brand blue, or takes a pale blue fill, the way a menu library draws its items. The browser's focus outline didn't fit the look, so the stylesheet removed it, and focus was given the hover style instead.
So when you Tab down the list, focus is there: each link in turn turns blue, or takes the pale fill. You can see it if you know what to look for and the colours are clear to you. If they aren't, the list looks the same as it did before you pressed Tab, and you press Enter without knowing which page will open.
WCAG 1.4.1 Use of Color doesn't allow colour to be the only visual means of telling something apart, and which link has focus is one of those things. Its Understanding document accepts two colours as a distinction of their own only when they differ in lightness, not only in hue, by a contrast ratio of 3:1 or more.
- The grey link text,
#4d4d4d, and the brand blue it turns,#1a4fd0, are 1.24:1 apart. They are a different hue at almost the same lightness. - The pale fill,
#dbeafe, is 1.22:1 against the white it replaces.
A darker shade of the same text can't get there either: #4d4d4d turned fully black is 2.48:1 apart. Text this dark, 8.45:1 on white, is too close to black for a change of its colour alone to reach 3:1.
The criteria that look closer don't catch it. 2.4.7 Focus Visible asks only that a focus indicator be visible, and a change of colour is something to see. 1.4.11 Non-text Contrast doesn't compare a control's focused and unfocused states, and its Understanding document puts a change of colour within the component outside its scope, adding in Figure 15 that it "would not pass Use of color". That is where it fails.
Anyone looking at a glossy phone screen in daylight, or a laptop turned down to save battery, loses a 1.2:1 change first. A greyscale mode, which some people turn on to reduce distraction, removes the blue altogether.
3 of 10 groups affected
- No vision (not affected)
- Low vision (affected)
- Colour vision (affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (not affected)
- Seizures (not affected)
- Without perception of colour A grey that turns blue can look the same grey to someone with a colour vision deficiency, or in a greyscale display mode: the two colours differ in hue, not in lightness, so nothing changes where they look.
- Limited vision People with low vision, or with reduced contrast sensitivity, look for a change and pass over a pale fill at 1.22:1, which is close to the white around it. With magnification, only part of the list shows, and there is nothing to compare the focused link with.
- Limited manipulation Keyboard and switch users have to know which link focus is on before they press Enter. When they can't tell, they press and see where they land.
Scanners that read the page as it loads, such as axe, never focus anything, so they don't see a focus style at all. The audit does: it focuses up to 25 controls on each page and compares each one's computed styles and a picture of it before and after. When only colours changed, it measures the change, and under 3:1 it reports focus shown only by colour, at the 1.4.1 criterion. It finds both Befores here. It doesn't reach a link that only appears in a closed menu, a dialog or the next slide, and a style that only a hover draws is not measured. A quick fix that adds :focus to an existing hover rule, the way both Befores are written, looks like focus was handled, and it passes code review.
Try it
Press Tab down the account links, then turn on Greyscale and try again
Broken 1: focus only turns the link’s grey text blue, 1.24:1 apart. In greyscale, the focused link looks like the rest.
Broken 2: focus only gives the link a pale blue fill, 1.22:1 against the white. Look for it on a dim screen.
Apply a fix. Tab down the links again, in colour and in greyscale: the focused one stands out in both.
Broken Can you fix this?
Orders
You have no orders yet.
The fix
Show focus with more than a faint change of colour
The link text turns brand blue
<nav class="account-nav" aria-label="Your account"> <ul> <li> <a href="/orders">Orders</a> </li> <li> <a href="/saved">Saved items</a> </li> <li> <a href="/addresses">Addresses</a> </li> <li> <a href="/payment">Payment methods</a> </li> </ul></nav>What is wrong3 points
- The outline is removed, and focus only turns the text from
#4d4d4dto#1a4fd0. - The two colours are 1.24:1 apart, so the change is in hue alone.
- In greyscale, or to someone who doesn't see the blue, the focused link looks like the others.
A focus ring beside the colour
<nav class="account-nav" aria-label="Your account"> <ul> <li> <a href="/orders">Orders</a> </li> <li> <a href="/saved">Saved items</a> </li> <li> <a href="/addresses">Addresses</a> </li> <li> <a href="/payment">Payment methods</a> </li> </ul></nav>How it is fixed3 steps
- Keep the blue text on hover and on focus: the design's colour change stays.
- Draw a 2-pixel outline in the brand blue on
:focus-visible, 2 pixels outside the link. It is 6.83:1 against the white page, and it is a shape, so it shows whatever colours a person sees. - Use
:focus-visiblerather than:focus, so a mouse click doesn't draw the ring.
This fixes both Befores and passes 1.4.1. The same outline goes on the pale fill version: keep the fill, and add the ring around it. A contrast theme keeps the outline and draws it in its own colour.
All three pass 1.4.1. Use the focus ring: it is the only one that works the same on every kind of control (a word, an icon, a card) and in a contrast theme without anything extra, and it keeps the design's colour change. The strong fill suits a menu or a list whose items are meant to look like rows, and needs its transparent outline and white text checked on every fill colour. The underline is the smallest change for a list of text links, but an icon link or a button has nothing to underline.
A change of colour can still be the whole focus style when the two colours are 3:1 apart. The missing focus indicators guide's design ideas include a button that fills with its own line colour on focus: the change from white to navy is far more than 3:1. What fails is a change of hue at the same lightness, and a tint so pale it barely differs from the page.
Hover and focus can share a style, as the first and third Afters do, as long as the shared style passes. Sharing it is what spread the failure here: the hover style was chosen for a mouse, where the pointer itself shows where you are, and focus inherited it.
A ring drawn outside the link has to contrast with what it sits on, which is low-contrast focus rings against the background. A list inside a box that clips its contents, such as a scrolling panel, can cut an outside ring off; draw it inside the link with a negative outline-offset there, against the link's own fill.
This guide is about focus shown only by colour. A control with no focus style at all is missing focus indicators, and a status told apart by colour alone is status dots told apart by colour alone.
Design ideas
Focus can keep a quiet look and still show without colour
Four more ways to draw focus on the same account links. Press Tab through each: two add a shape, and two change only colour.
In the design file
- Draw each link focused beside the same link at rest, and name what changes besides colour, such as a bar, a mark, an outline or an underline.
- Where focus changes only a colour, write the ratio between the colour before and after, at least 3:1. The example’s grey to blue is only 1.24:1.
- Look at the focused frame in greyscale. If the focused link looks like the others, add a shape.
- Draw focus apart from hover, since the pointer shows where the mouse is and only the focus style shows where the keyboard is.
Passes
- Bar along the edge A 4px bar in the brand blue appears along the focused link’s start edge, 6.83:1 against white, and the words turn blue beside it. The bar is a shape, so it shows in greyscale, and drawn as a border it stays in a Windows contrast theme.
- Chevron that appears A small chevron in the text colour appears before the focused link’s words. Keep its space empty at rest, so the words don’t move when it appears. It is a new shape, not a new colour, so nothing depends on seeing the blue.
Fails
- The other links dimWCAG 1.4.1 When focus enters the list, every other link fades to 60% and the focused one stays #4d4d4d. The faded grey is #949494, only 2.79:1 from it, so the one difference is a lightness under 3:1, and nothing else marks the link.
- Gradient textWCAG 1.4.1 Focus fills the words with a purple to blue gradient, #6d28d9 to #1a4fd0. Both ends are almost as dark as the grey they replace, 1.19:1 and 1.24:1 from #4d4d4d, so in greyscale the focused link looks the same as the others.
Verify the fix
4 checks, no mouse.
Test with: Keyboard, Contrast measurement, Colour vision simulation, Forced colors
Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the theme's colours or shared component styles change.
Limits
This is a starting pattern, not a guarantee for every application. The colours are examples; measure your own before and after colours on your real surfaces. A focus style that passes 1.4.1 can still be hard to find if it is thin or faint, and 2.4.13 Focus Appearance, at Level AAA, asks for more, as focus rings too thin or faint to spot explains. Test the complete journey with people who rely on seeing focus.
This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.