# Focus states shown only by a change of colour

Source: https://easeweb.dev/learn/colour-only-focus
Topics: Colour and contrast > Status, selection and charts are shown by more than colour (WCAG 1.4.1)
The fix: Show focus with more than a faint change of colour. Either keep the colour change and add a focus ring, make the focused fill differ from the unfocused one by 3:1 or more, or add an underline as the colour changes.
Test with: keyboard, contrast measurement, colour vision, forced colors
References: https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html https://www.w3.org/WAI/WCAG22/Understanding/focus-visible.html https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible

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.

## What happens

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.

## Why it fails

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.

## Who is affected

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.

## What automation and AI miss

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.

## Before: the link text turns brand blue

```html
<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>
```

```css
.account-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: #4d4d4d;
  text-decoration: none;
}
.account-nav a:hover,
.account-nav a:focus {
  /* The hover style, shared with focus */
  color: #1a4fd0;
  outline: none;
}
```

- The outline is removed, and focus only turns the text from `#4d4d4d` to `#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.

## Before: the link takes a pale blue fill

```html
<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>
```

```css
.account-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: #4d4d4d;
  text-decoration: none;
}
.account-nav a:hover,
.account-nav a:focus {
  /* A pale fill, as menu libraries draw a focused item */
  background: #dbeafe;
  outline: none;
}
```

- The outline is removed, and focus only fills the link with `#dbeafe`.
- The fill is 1.22:1 against the white it replaces, so it is close to invisible on a dim or bright screen.
- A Windows contrast theme removes the fill, and then focus doesn't show at all.

## After: a focus ring beside the colour

```html
<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>
```

```css
.account-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: #4d4d4d;
  text-decoration: none;
}
.account-nav a:hover,
.account-nav a:focus-visible {
  color: #1a4fd0;
}
.account-nav a:focus-visible {
  /* A ring that colour vision doesn't decide */
  outline: 2px solid #1a4fd0;
  outline-offset: 2px;
}
```

1. Keep the blue text on hover and on focus: the design's colour change stays.
2. 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.
3. Use `:focus-visible` rather 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.

## After: a fill that changes the lightness by 3:1

```html
<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>
```

```css
.account-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: #4d4d4d;
  text-decoration: none;
}
.account-nav a:hover {
  background: #dbeafe;
}
.account-nav a:focus-visible {
  /* A strong fill, with white text on it */
  background: #1a4fd0;
  color: #fff;
  /* Drawn only by a contrast theme, which removes the fill */
  outline: 2px solid transparent;
}
```

1. Fill the focused link with the brand blue, `#1a4fd0`. It is 6.83:1 against the white it replaces, so the change is in lightness, not only in hue, and 1.4.1 accepts it.
2. Turn the text white. It keeps 6.83:1 against the new fill, above the 4.5:1 that text needs.
3. Keep the pale fill for hover only, so hover and focus no longer look the same.
4. Add a transparent outline. It draws nothing on a normal screen, but a Windows contrast theme removes the fill and draws the outline in its own colour, so focus still shows there.

This fixes both Befores and passes 1.4.1 with no ring, keeping the design's idea of a fill. Set `outline: none` there instead and the fix still passes WCAG, but focus disappears in a contrast theme.

## After: an underline beside the colour

```html
<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>
```

```css
.account-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: #4d4d4d;
  text-decoration: none;
}
.account-nav a:hover,
.account-nav a:focus-visible {
  color: #1a4fd0;
  /* A line under the words, not only a new colour */
  text-decoration: underline 2px;
  text-underline-offset: 4px;
  outline: none;
}
```

1. Keep the blue text on hover and on focus.
2. Underline the link's words on both, 2 pixels thick and 4 pixels below the baseline. The line is a shape: in greyscale, and to someone who doesn't see the blue, the focused link is the underlined one.
3. Use `:focus-visible`, so the underline follows the keyboard and not a click.

This fixes the first Before and passes 1.4.1 with the lightest change to the design. A contrast theme keeps the underline. It suits links made of words; a link that is only an icon has nothing to underline, so it needs the ring or the fill.

## Which option to use

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.

## Implementation decisions

A change of colour can still be the whole focus style when the two colours are 3:1 apart. The [missing focus indicators](/learn/visible-focus) 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](/learn/focus-ring-contrast). 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](/learn/visible-focus), and a status told apart by colour alone is [status dots told apart by colour alone](/learn/status-colours).

## Verify the fix

1. Tab through every link and button in both directions, and confirm that something other than a faint change of colour marks the focused one: an outline, an underline, a change of shape, or a fill much darker or lighter than before.
2. Where focus only changes a colour, pick the colour before and after with a contrast checker's eyedropper, the text or the fill, and confirm they are at least 3:1 apart, and that text on a new fill keeps 4.5:1.
3. Turn on a greyscale filter, Tab through again, and confirm the focused control can still be told apart.
4. Turn on a Windows contrast theme, and confirm focus still shows on every control.

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](/learn/focus-appearance) explains. Test the complete journey with people who rely on seeing focus.

---

Get this guide in your coding agent: MCP https://easeweb.dev/mcp (setup at https://easeweb.dev/services/developers)
