To find out whether a text color passes WCAG AA or AAA, turn each of the two colors into a relative luminance between 0 and 1, divide the lighter value plus 0.05 by the darker value plus 0.05, and hold the outcome against the bar set for that kind of text. Level AA asks for 4.5 to 1 on normal text and 3 to 1 on large text; level AAA asks for 7 to 1 and 4.5 to 1 (W3C, Contrast (Enhanced)). A good color contrast checker does exactly this sum, and this guide shows it by hand so you can tell what a tool is doing, and when its answer is about the wrong pair.
What a color contrast checker actually computes
The calculation is two steps, each fixed by the WCAG 2.2 text. First, every color becomes a single brightness number called relative luminance. Second, two such numbers become one contrast ratio. Nothing else enters the calculation: not hue, not how the color looks on your screen, not font weight.
For luminance, each of the red, green and blue channels is read as a value from 0 to 255 and divided by 255. A very small value is divided by 12.92; a larger one is shifted by 0.055, divided by 1.055 and raised to the power 2.4. That undoes the gamma curve of sRGB and gives light intensity that can be added. The three results are then weighted by how strongly the eye responds to each: 0.2126 for red, 0.7152 for green and 0.0722 for blue (WCAG 2.2, relative luminance). Green dominates, which is why a mid green and a mid blue with the same channel value differ so much in brightness.
For the ratio, the spec adds 0.05 to both luminances and divides the lighter by the darker. Possible results start at 1, which is one color against itself, and stop at 21, the figure for the darkest black against the lightest white, as the same definitions page states. The 0.05 stops the division blowing up near black and stands in for a little stray light on the screen.
The thresholds: AA, AAA and the 3:1 group
The three W3C pages give three different bars, and mixing them up is the most common reading error.
| What you check | AA | AAA |
|---|---|---|
| Normal text | 4.5 : 1 | 7 : 1 W3C |
| Large text | 3 : 1 | 4.5 : 1 W3C |
| Controls and meaningful graphics | 3 : 1 | no separate level |
The first two rows come from the pages for Contrast (Minimum) and Contrast (Enhanced). The last row comes from Non-text Contrast, which asks 3 to 1 against the adjacent colors for the visual information a person needs to find a control and see its state, such as an input border or the check in a checkbox. That criterion sits at level AA, so there is no stricter version to aim for.
Large text is defined in points, not pixels: 18 point, or 14 point when bold (W3C, Contrast (Minimum)). Converting at 4 pixels to 3 points gives 24 pixels, or about 18.7 pixels when bold. A heading at 20 pixels in regular weight is therefore still normal text. Two more rules decide how a verdict is written. A computed figure is used as it comes, with no rounding in the page's favour: the W3C notes say a result just under the bar, such as 4.499, falls short of 4.5, and the same note appears on all three pages. And some things carry no requirement at all: text in an inactive component, pure decoration, text nobody can see, and logos and brand names.
Worked by hand: one grey, two backgrounds
Take the text color #6b7280, a common mid grey for secondary text, and two backgrounds: white, and the pale panel color #f3f4f6. Using the formulas in WCAG 2.2, the channels of the text are 107, 114 and 128. After the gamma step they become about 0.1470, 0.1683 and 0.2159. Weighting them gives 0.1470 times 0.2126, which is 0.03126, plus 0.1683 times 0.7152, which is 0.12034, plus 0.2159 times 0.0722, which is 0.01559. The sum is a luminance of about 0.1672. White is 1.0 by definition, and the panel color works out to about 0.9041 by the same route.
On white the ratio is 1.05 divided by 0.2172, which is 4.83. That clears 4.5, so it passes AA for normal text, and it falls short of 7, so it fails AAA. On the panel the ratio is 0.9541 divided by 0.2172, which is 4.39. The text did not change, the panel is only slightly off white, and the pair has moved from pass to fail. These steps follow the W3C definitions; a short script running the same formulas gave 4.83 and 4.39 to two places, matching the hand sums.
To repair the panel case without guessing, solve the ratio backwards, using the same definition. The text luminance must be no higher than the panel luminance plus 0.05, divided by 4.5, minus 0.05; that is about 0.1647, and #6b7280 sits a little above it. Trying #595f6b, a slightly darker grey, gives a luminance of about 0.1137 and a ratio of 5.83 on the panel, which passes AA with room to spare. Whichever color you pick, compute the pair once more before you trust it.
Pitfalls that make a checker look wrong
Most disputes about WCAG color contrast are not about the formula; they are about which two colors were fed into it.
- The background is the nearest one behind the text. Words inside a card are judged against the card's fill, not the page's. The grey above is fine on white and wrong on the panel, and a tool given only the page color will say pass for both.
- Transparency has to be flattened first. Semi-transparent text, or text on an element with an opacity setting, mixes with whatever lies behind it. The ratio belongs to the mixed color, so work out the blend per channel before the luminance step. A checker that reads only the raw color value misses this.
- Gradients and images have no single background. Test the worst spot behind the text, or put a solid layer under it.
- Placeholders are text. A light grey hint inside an empty field has to meet the same bar as other text, even though it is easy to treat as decoration.
- States count as well. Hover, focus, selected and error colors each need their own check; the non-text page says a component must not lose contrast with its neighbours.
- Dark mode is a second palette. Every pair has to be recomputed, because passing in light says nothing about the other theme.
Color is also only one slice of accessibility. A page can pass every ratio and still have images with no text alternative or controls a keyboard cannot reach, which is what an LLM review of accessibility problems tends to bury. And if your page animates, colors are not the only thing a visitor with low vision or a vestibular disorder will notice; see how reduced-motion rules often go wrong for that side.
A test that can come out red
Never trust a contrast tool that you have only seen answer "pass". Try these steps.
- List the pairs from the real stylesheet, with the background of the element that actually sits behind each text, not the body color.
- Compute each ratio, by tool or by hand, and write down both the number and the threshold it was compared with.
- Feed the tool a pair you know fails, such as
#999999on white, and one you know passes, such as black on white. A tool that cannot tell these apart is not measuring. - Feed it a pair that lands just under a limit, such as
#777777on white, which works out near 4.48. If it passes that, it rounded the result up, which the W3C notes rule out. - Put a semi-transparent text color through it. If the number matches the raw color, the tool ignored the blending.
When this does not apply
The ratio is a floor, not a guarantee of readability. It says nothing about font size or weight beyond the large-text split, nothing about thin strokes or glare, and a pair right at the bar can still be tiring to read. The formula assumes sRGB, which the WCAG definitions say to use unless another color space is known to be in play. People with some kinds of low vision also find very high contrast, such as pure white on pure black, harder, so AAA is not always better for every reader. Finally, one pair was computed by hand and with one script. That checks the arithmetic, not any particular tool, and the W3C pages may have changed since 26 November 2026.
Our skills for this topic
- wcag-color-contrast-check takes pasted CSS or a palette, works out each pairing of text and fill, states whether it clears AA and AAA, and proposes a replacement color where a pair fails.
- accessibility-review reads pasted HTML or JSX for the markup defects that screen reader and keyboard users meet first, and names the WCAG criterion for each.
- css-motion-review reads CSS for motion that starts on its own, runs on without a pause control, or ignores a reduced-motion setting.
- form-input-ux-review reads one form for typing mistakes such as blocked paste or a submit button that stays disabled too long.
Read this post as Markdown: /blog/color-contrast-checker-wcag-aa-aaa.md · Atom feed.
