WCAG 2.2 for links

Links on colored backgrounds Every state, every criterion

A link has to stand out from the background, from the text around it, and in every state: at rest, visited, on hover and with the keyboard's focus ring. On most colored backgrounds color alone cannot do all of that, and this workbench shows why, measures each state against its own criterion, and writes the CSS that passes.

What you get

  1. Every state measured The link at rest, visited, on hover and focus, and its focus ring, each against the background.
  2. Each criterion on its own 1.4.3 for contrast, 1.4.1 for telling links from text, 1.4.11 and 2.4.13 for the focus ring.
  3. The room color leaves A chart of every lightness of your link's hue, and where, if anywhere, it works without an underline.
  4. CSS that passes A recipe for the band and its links in every state, with the nearest fixes one click away.

The workbench

Measure links on a background

Set the background, the text and the link in each state, choose how links are underlined, or open an example. Every change is measured again at once.

The workbench needs JavaScript. The worked examples below read without it.

The four states, painted by your browser #1D4ED8

Result

AA

Fails

Checks failing: 3 Checks counted: 7

Each check, the WCAG criterion behind it, the pair measured and the result
CheckCriterionPairContrastNeedsResult
Body text on the background1.4.3 AA6.70:14.5:1Passes
Link on the background1.4.3 AA3.71:14.5:1Fails
Hover and focus color on the background1.4.3 AA5.49:14.5:1Passes
Visited link on the background1.4.3 AA4.82:14.5:1Passes
Link against the body text, without an underline1.4.1 A1.38:13:1Fails
A cue besides color on hover and focus1.4.1 A—An underline or another cueFails
Focus ring against the background1.4.11 AA3.71:13:1Passes
Focus ring 2 px or thicker, at 3:12.4.13 AAA3.71:13:1Passes
Body text on the background
6.70:1
Color alone would need
13.5:1
Link colors that work without an underline
None on this background
Every lightness of the link's hue, measured against the background and against the body text. Shaded green: where a link color passes for this design, against both lines without an underline, against the background alone with one; the dot is your link.

Underline

Underline links at rest, so color is not the only cue.

Nearest link color without an underline

None: the body text would need 13.5:1 on the background for a link color to stand apart from it.

Nearest link color, underlined

#B5D8FF 4.54:1

Nearest visited color

No lightness of this hue gets there.

CSS for this design

.band {
  background-color: #1D4ED8;
  color: #FFFFFF;
}
.band a {
  color: #93C5FD;
  text-decoration: none;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
.band a:visited {
  color: #DDD6FE;
}
.band a:hover,
.band a:focus-visible {
  color: #DBEAFE;
}
.band a:focus-visible {
  outline: 2px solid #93C5FD;
  outline-offset: 2px;
}

Background and text
Link colors
Underline
Focus ring

Drawn as an outline 2 px outside the link, so the background is on both sides of it.

Text
Measure

Worked examples

Five link designs, measured

Each design is measured at level AA for its text size. Open one in the workbench to change anything.

Five link designs: the link on its background, against the body text and its focus ring, the result and a fix
DesignBackground, text, linkUnderlineLink on the backgroundLink against the textFocus ringResultA fixWorkbench
Links on a white page #FFFFFF#111827#2563EB Never 5.16:1 3.11:1 5.16:1 Fails 1.4.1 Underline on hover and focus
A brand blue banner #1D4ED8#FFFFFF#93C5FD Never 3.71:1 1.38:1 3.71:1 Fails 1.4.3, 1.4.1 Underline at rest and link #B5D8FF
A dark footer #111827#9CA3AF#60A5FA On hover and focus 6.97:1 1.00:1 6.97:1 Fails 1.4.1 Underline at rest
A warning callout #FEF3C7#78350F#B45309 On hover and focus 4.50:1 1.24:1 4.50:1 Fails 1.4.1 Underline at rest
A green promo band #166534#FFFFFF#FFFFFF Always 7.13:1 1.00:1 2.16:1 Fails 1.4.11 Focus ring #42C065
  • White leaves room for color. Near-black text reaches 17.73:1 on white, more than the 13.5:1 color alone needs, so the blue link stands 3.11:1 apart from it. It still needs a cue on hover and focus, such as an underline.
  • A colored band leaves none. White text on the brand blue reaches 6.70:1, so no link color can clear the blue by 4.5:1 and the text by 3:1 at once; the pale blue link is 1.38:1 from the text. Underline it.
  • Hue is not contrast. In the dark footer the blue link and the gray text measure 1.00:1 against each other: only their hue differs, which many readers cannot see.
  • An underline on hover comes too late. The callout's underline appears on hover, but at rest the link is told from the text by color alone, at 1.24:1.
  • The focus ring needs 3:1 too. A green ring on the green band measures 2.16:1; a lighter green, #42C065, reaches 3:1.

Method

How it measures

  1. The body text and the link in each state, at rest, on hover and focus, and visited, are measured on the background with WCAG 2's ratio: 4.5:1, or 3:1 for large text; 7:1 and 4.5:1 at level AAA.
  2. Without an underline at rest, the link and the visited link are measured against the body text, which technique G183 sets at 3:1, and the link must show a cue besides color on hover and focus. An underline is that cue, and with one at rest the link is not told apart by color alone.
  3. The focus ring is drawn outside the link with an offset, so the background surrounds it: it must differ from the background by 3:1 (1.4.11), and at level AAA be at least 2 px thick too (2.4.13).
  4. The chart takes the link's hue and chroma in OKLCH and measures every lightness against both the background and the text; where both pass, a link color works without an underline.
  5. Each fix keeps its color's hue and chroma and moves only its lightness, by the smaller step that passes.

Why a colored band leaves no room: a link between the text and the background in lightness must clear the background by 4.5:1 and the text by 3:1. Contrast ratios multiply along that line, so the text must already reach 4.5 × 3 = 13.5:1 on the background; at level AAA it would take 7 × 3 = 21:1, which only black on white reaches.

The worked examples are recomputed by an automated test from the same code, so a figure on this page cannot drift from what the workbench measures.

Found a wrong number? Tell us.

Limits

What a measurement cannot tell you

  • G183 is one way to meet 1.4.1, not the only one. An underline, an icon, a heavier weight or a border also tell a link apart without color.
  • Links in menus and lists are a different case. 1.4.1 is about links inside running text; in a navigation bar, where everything is a link, there is no body text to tell them from.
  • The ring is assumed to sit on the background. A ring drawn against the link's own fill, or a focus style that changes the background instead, must differ from what is next to it, which this page does not draw.
  • Browsers restrict visited styles. Only colors can change on :visited, and scripts read the unvisited color for privacy; this page measures the color you set.
  • Touch screens have no hover. On a phone, the cue that matters is the one at rest and in focus.
  • Only flat backgrounds are measured. For links over a photo or a gradient, measure with Text on an image or Text and gradients.

In practice

Making links clear on any background

  1. Underline links in running text. It is the one cue that works on every background, in every theme, for every reader.
  2. Keep the underline light and lift it on hover. A 1 px line offset by 0.2em reads cleanly; thicken it to 2 px on hover and focus.
  3. On a colored band, let links share the text color. The text already passes on the band; the underline marks the link, and the color can stay calm.
  4. Give the focus ring its own color. White or near-black usually clears a mid-tone band by 3:1 where a tint of the band does not; offset it by 2 px.
  5. Check visited links and hover colors as well. A pale visited color is the state most often left failing.

The rules: 1.4.1 Use of Color, 1.4.3 Contrast (Minimum), 1.4.11 Non-text Contrast, 2.4.7 Focus Visible and 2.4.13 Focus Appearance.

Where next

Check the rest of the page

From links to every pair on a page.