Color Contrast Explained

Contrast is the single most important color decision for accessibility. This guide explains exactly how the WCAG contrast ratio is calculated, what the thresholds mean, and how to test any pair of colors.

By COOLOUR Editorial Team Published Updated

What contrast ratio means

Contrast ratio is a numeric measure of the perceived difference in lightness between two colors. It runs from 1:1 (identical colors, no contrast) to 21:1 (pure black on pure white, maximum contrast).

Contrast is not a measure of hue difference. Red and green can be equally bright — in which case they have a contrast ratio near 1:1, even though they look extremely different to most people. WCAG contrast requirements are about luminance, because that is what matters for legibility.

The formula

The WCAG contrast formula is defined in the Web Content Accessibility Guidelines and is the same across WCAG 2.0, 2.1 and 2.2:

ratio = (L1 + 0.05) / (L2 + 0.05)

where L1 is the relative luminance of the lighter color and L2 is the relative luminance of the darker color.

Relative luminance

Relative luminance is a weighted sum of the linearized RGB channel values:

L = 0.2126 × R_lin + 0.7152 × G_lin + 0.0722 × B_lin

Where R_lin, G_lin and B_lin are the linearized channel values, obtained by applying the following to each channel's sRGB value (normalized to 0–1):

if c ≤ 0.04045: c_lin = c / 12.92
else:           c_lin = ((c + 0.055) / 1.055) ^ 2.4

The weights — 0.2126, 0.7152, 0.0722 — reflect the human eye's sensitivity to each channel. Green contributes most to perceived brightness, blue least.

The WCAG thresholds

LevelContent typeMinimum ratio
AANormal text4.5:1
AALarge text (≥18pt or ≥14pt bold)3:1
AAUI components and graphical objects3:1
AAANormal text7:1
AAALarge text4.5:1

For most projects, AA is the target. AAA is worth pursuing where it doesn't compromise the design.

Common failures

The most common contrast failures we see in real projects:

  • Light gray text on white. A huge percentage of design templates use #999999 or lighter for body text on white. This fails AA at 2.85:1.
  • Placeholder text. Same problem — placeholders are often too light.
  • Brand color as text. Many brand colors look great as a button but fail as text on white. Always test both.
  • White text on yellow. Yellow is very bright — white text fails at almost any yellow value.
  • Colored text on colored backgrounds. Two mid-saturation colors often have surprisingly low contrast.
  • Disabled states. Often deliberately low-contrast, but should still be visually distinguishable from the enabled state.

How to check contrast in practice

Three approaches, in order of convenience:

  1. Use our Contrast Checker. Paste two HEX values and get the exact ratio with AA/AAA pass/fail.
  2. Use our WCAG Accessibility Checker. Get a full compliance report for every relevant criterion, with a copy-ready statement.
  3. Compute it manually from the formula above — useful when you're automating contrast checks in a build pipeline.

Contrast in different contexts

Text on gradient backgrounds

A gradient has different contrast against text at every point. Test the text against both ends of the gradient — and ideally the midpoint too.

Text on images

Text over images is unpredictable. Use a semi-transparent overlay behind the text, or place the text on a solid panel that guarantees contrast regardless of the image.

Small text

WCAG's 4.5:1 threshold applies to "normal text", which starts at around 14pt (18.66px). Text smaller than that is still required to meet 4.5:1, but users often find smaller text harder regardless — consider raising the threshold to 5:1 or more for text below 12px.

Why "just barely passing" is often not enough

A pair that passes 4.5:1 on a calibrated monitor might fail on a phone in bright sunlight, on a cheap laptop display, or after a user activates a low-contrast accessibility mode. Aim to exceed the minimum by a margin — 5:1 or higher for body text — to give yourself headroom.

FAQ

How is contrast ratio calculated?
Ratio = (L1 + 0.05) / (L2 + 0.05), where L1 and L2 are the relative luminances of the two colors.
What contrast ratio should I aim for?
AA requires 4.5:1 for normal text and 3:1 for large text and UI. AAA requires 7:1 and 4.5:1. Aim for at least 5:1 for body text in practice.
Does hue matter for contrast?
No — contrast ratio is based entirely on relative luminance, not hue. Two colors with different hues but equal lightness have contrast ratio near 1:1.