Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 38 ยท Colour, Contrast and Media

Color Contrast Ratios

Learn how WCAG measures color contrast, the 4.5:1 and 3:1 thresholds, how to compute a ratio in JavaScript, and how to fix low-contrast text and UI.

Text that is hard to read is useless to many people. Low vision, aging eyes, glare from a window, a cheap laptop screen, or a dim phone in sunlight all reduce how much contrast a person can see. WCAG turns "easy enough to read" into a number you can measure: the contrast ratio between two colors.

This lesson explains how the ratio works, which thresholds apply to text and to interface parts, and how to calculate a ratio yourself so that you understand what checking tools report.

What the ratio means

A contrast ratio runs from 1:1 (identical colors, invisible) to 21:1 (black on white). It compares the relative luminance of the lighter and darker color, which is a measure of how bright each color looks to the eye (green counts most, blue least).

The formula is:

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

where L1 is the luminance of the lighter color and L2 of the darker one. The 0.05 models ambient light on the screen.

Hue does not matter by itself. Two colors with the same brightness, such as a mid red and a mid green, can have a ratio near 1:1 even though they look very different to someone with full color vision.

The thresholds

Success criterion Level What it covers Minimum
1.4.3 Contrast (Minimum) AA Normal text 4.5:1
1.4.3 Contrast (Minimum) AA Large text 3:1
1.4.6 Contrast (Enhanced) AAA Normal text 7:1
1.4.6 Contrast (Enhanced) AAA Large text 4.5:1
1.4.11 Non-text Contrast AA UI component boundaries and states, meaningful graphics 3:1

Large text means at least 24 CSS px (18pt) regular, or 18.66 CSS px (14pt) bold. Most body copy is not large.

Exceptions: pure decoration, text inside inactive (disabled) controls, logos and brand names, and text in a photograph that you cannot control. Do not abuse these. A "disabled-looking" link that is really active still needs full contrast.

Round down, never up. A ratio of 4.49:1 fails the 4.5:1 requirement. There is no rounding in WCAG.

Calculate it yourself

The steps are: convert each sRGB channel to a linear value, weight the channels, and apply the formula. The demo below does exactly that. Change the two colors and watch the verdict.

Contrast ratio calculator

The starting pair, #767676 on white, is about 4.54:1. It is the lightest neutral gray that passes AA on white, which is why you see it in many design systems. #777777 is about 4.48:1 and fails.

Fixing a failing pair

Usually you darken the text or lighten the background until the ratio passes, and keep the hue so the brand still feels the same. Compare these cards.

Before and after

Contrast for interface parts and states

1.4.11 asks for 3:1 against adjacent colors for anything a user needs to see to operate the page:

  • The border of a text input (if the border is the only thing marking the field).
  • The visible state of a checkbox, radio, toggle or slider handle.
  • Focus indicators (see focus visibility in the next lesson for the color side).
  • Icons that carry meaning without a text label.

A light gray input border on a white page (#d0d0d0, about 1.5:1) is a classic failure, even though the placeholder text may pass.

Tricky cases

  • Text over images or gradients. Test the worst spot behind the text. Add a solid or semi-opaque panel behind the text rather than hoping for a good crop.
  • Opacity. opacity: 0.6 mixes the text with the background; measure the resulting color, not the declared one.
  • Dark mode. Pass in both themes. Pure white on pure black can glare, so many designs use #e6e6e6 on #121212 (about 14:1), which is still far above the limit.
  • Hover and disabled states that look like normal state must also pass if they convey information.
flowchart LR
  A["Pick text and background"] --> B["Measure ratio"]
  B --> C{"4.5:1 or 3:1 (large text, UI)?"}
  C -- "yes" --> D["Done"]
  C -- "no" --> E["Darken text or lighten background"]
  E --> B

Adjust until the ratio passes, then check the other states.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the minimum contrast ratio for normal body text at WCAG level AA?

    Success criterion 1.4.3 requires 4.5:1 for normal text. 3:1 is for large text and UI parts; 7:1 is the AAA level.
  2. 2. Which text counts as large text?

    Large means 14pt bold (about 18.66 CSS px) or 18pt (24 CSS px) regular. Headings are not automatically large.
  3. 3. A text input has a 1.5:1 border and no other visible edge. Which criterion does it most likely fail?

    1.4.11 requires 3:1 for the visual boundary of a control when that boundary is needed to identify it.
  4. 4. A measured ratio is 4.49:1. Does it meet the 4.5:1 requirement?

    The threshold is a hard line. 4.49:1 fails, so darken the color a little more.

Summary

  • Contrast ratio goes from 1:1 to 21:1 and is based on relative luminance.
  • Normal text needs 4.5:1 (AA) or 7:1 (AAA); large text and UI parts need 3:1.
  • Test text on images, with opacity, in every state, and in both themes.
  • Fix failures by adjusting lightness while keeping the hue.

Next: Not Relying on Color Alone