Skip to content

Guide

How the WCAG contrast ratio is calculated

Every contrast checker gives you a number like 4.54:1. Here is exactly where that number comes from, why the limits are where they are, and the cases the rules don’t cover.

By Mark Stoumann ·

The Web Content Accessibility Guidelines (WCAG) don’t ask whether two colors look different; they ask whether they differ enough in brightness. Hue doesn’t count at all. That surprises people, and it explains most of the strange results a contrast checker gives: red and green that look nothing alike can still “fail” against each other.

Step 1: relative luminance

WCAG 2.2 first turns each color into a relative luminance, a number from 0 for black to 1 for white. It takes three steps:

  1. Divide each RGB channel by 255, so it runs from 0 to 1.
  2. Undo the screen’s gamma curve. Values up to 0.04045 are divided by 12.92; larger values become ((value + 0.055) ÷ 1.055)2.4. This turns the stored numbers back into amounts of light.
  3. Weight the channels by how bright they look and add them: 0.2126 × red + 0.7152 × green + 0.0722 × blue.

The weights are the key. Green counts almost ten times as much as blue, because our eyes are far more sensitive to it. That is why pure blue is a “dark” color for contrast purposes and pure yellow a very light one.

If you have seen the threshold written as 0.03928 in older code, that is not a mistake in ColorPeekr. WCAG used that value until May 2021, when it was changed to 0.04045. The W3C notes the change makes no practical difference to results.

Step 2: the ratio

With both luminances known, the contrast ratio is (lighter + 0.05) ÷ (darker + 0.05). The 0.05 added to both sides stops the ratio from shooting to infinity as the darker color nears pure black. The result runs from 1:1 to 21:1.

A worked example: #0066cc on white

ChannelValue÷ 255Linear light× weight
Red00.00000.00000.0000
Green1020.40000.13290.0950
Blue2040.80000.60380.0436

The luminance of #0066cc is 0.0950 + 0.0436 = 0.1386. White is 1. So the ratio is (1 + 0.05) ÷ (0.1386 + 0.05) = 1.05 ÷ 0.1886 ≈ 5.56:1. That passes AA for normal text (4.5:1) but not AAA (7:1). Notice that the blue channel, at twice the value of green, contributes less than half as much light.

Why 4.5:1, 3:1 and 7:1?

The thresholds come from research on reading, not from taste. The W3C’s explanation of the contrast criterion says 3:1 is the minimum recommended by the ISO 9241-3 and ANSI/HFES 100 ergonomics standards for people with normal vision. People with moderate low vision, about 20/40, lose contrast sensitivity by a factor of roughly 1.5, so AA asks for 3 × 1.5 = 4.5:1. AAA’s 7:1 does the same for vision loss of about 20/80.

Large text gets the lower numbers because bigger letters stay legible with less contrast. And the thresholds are exact: the W3C says the computed value must not be rounded, so 4.499:1 fails. This is why ColorPeekr rounds the displayed ratio down rather than to the nearest hundredth.

Surprising results, explained

Because only luminance counts, a few results confuse almost everyone:

  • Pure red on pure green (#ff0000 on #00ff00) reaches only 2.91:1, and red on CSS green (#008000) just 1.28:1, despite looking completely different. For someone with red-green color blindness, that low number is close to what they actually see; our color blindness guide explains why.
  • Mid-tones can’t win with both. Every color passes 4.5:1 with either black or white text, but no color reaches more than about 4.58:1 (the square root of 21) with both. #777777 works with black text (4.68:1) but misses on white (4.47:1); one step darker, #767676, passes with both, at 4.54:1 and 4.62:1.
  • White on orange is a common failure: on Okabe and Ito’s vermillion, #d55e00, white text reaches only 3.86:1, enough for large text but not for body copy.

What the rules cover, and what they skip

Three success criteria in WCAG 2.2 use the ratio. 1.4.3 Contrast (Minimum), level AA, covers text and images of text. 1.4.6 Contrast (Enhanced), level AAA, raises the bar. 1.4.11 Non-text Contrast, level AA, asks for 3:1 for the parts of controls you need to see to use them, such as an input’s border, a checkbox, or the focus outline, and for the parts of charts and icons you need to understand the content.

Some things are exempt, and knowing them saves arguments in design reviews:

  • Logos and brand names have no contrast requirement.
  • Inactive components, such as a disabled button, are exempt from both 1.4.3 and 1.4.11.
  • Pure decoration and text that isn’t visible to anyone are exempt.
  • Browser default controls you haven’t restyled fall under 1.4.11’s user agent exception.

A chart line that carries data is not decoration. If a reader must tell the line from the background to understand the chart, it needs 3:1, unless the same information is also given as text, such as data labels or a table.

Where the formula needs your judgment

  • Text over images and gradients. WCAG measures against the background the text actually sits on. Over a photo or gradient, test the lightest spot behind dark text (or the darkest spot behind light text), or put a solid or semi-transparent panel behind it.
  • Thin fonts. The W3C warns that very thin or unusual fonts can render much fainter than their color value suggests, because of anti-aliasing. A hairline font at a passing 4.6:1 can be harder to read than a regular weight at the same ratio; aim higher.
  • Large text. The 3:1 allowance starts at 18 point, or 14 point bold, which WCAG puts at roughly 1.2 to 1.5 times the default body size. Check your actual font: some typefaces look small for their size.

What about WCAG 3 and APCA?

The WCAG 2 formula has known limits. It treats light-on-dark and dark-on-light as equal, and it doesn’t consider font size and weight beyond the large-text cut-off. WCAG 3 is meant to address this, and you will often see APCA, the Accessible Perceptual Contrast Algorithm, mentioned as an alternative.

But as of the W3C working draft of 10 September 2026, WCAG 3’s contrast algorithm is still “to be determined”, and the draft itself says several years of work remain. Until a new version is published and adopted, WCAG 2.2’s ratio is the measure accessibility laws and audits use. Check your pairs with the contrast checker, which uses exactly the formula on this page.

Frequently asked questions

Why is the highest contrast ratio 21:1?

Black has a relative luminance of 0 and white of 1. Put those into the formula and you get (1 + 0.05) ÷ (0 + 0.05) = 21. No pair of colors can be further apart, so 21:1 is the ceiling and 1:1, a color against itself, is the floor.

Does it matter which color is the text and which is the background?

Not for WCAG 2. The formula always puts the lighter color on top, so dark gray on white and white on dark gray give exactly the same ratio. Your eyes may disagree a little, which is one of the things a future contrast method may address.

Is there a gray that works with both black and white text?

Only a narrow band. The best any color can do against both is the square root of 21, about 4.58:1, so a background that passes AA for normal text with both black and white must have a relative luminance between roughly 0.175 and 0.183. #767676 is one: 4.54:1 with white and 4.62:1 with black.

Do disabled buttons need to meet contrast requirements?

No. WCAG exempts text in inactive user interface components from 1.4.3, and inactive components from the 3:1 requirement in 1.4.11. Disabled controls should still be recognizable as controls, though, and many teams aim for at least 3:1 anyway.

Should I use APCA instead of the WCAG 2 ratio?

Not for compliance. WCAG 2.2 is the published standard, and the WCAG 3 working draft from September 2026 says its contrast algorithm is still to be determined. You can use other methods as an extra design check, but test against the WCAG 2 ratio when accessibility is a requirement.