WCAG Contrast Ratio Checker

Exact contrast for any two colours, and a fix.

  • AA, AAA and 3:1
  • Exact luminance maths
  • Nearest passing colour
A pale cream block and a dark charcoal block resting on the two ends of a flat clay seesaw balanced on a round clay stand, against a soft blurred light background

The guide

A Contrast Ratio Is a Threshold, So 4.478 Fails and 4.48 Must Not Be Read as 4.5

Two grey values one step apart sit on opposite sides of the AA line for text on white. Seeing why takes the luminance formula, its gamma step and a refusal to round.

  • 4.478089 grey #777777 on white: fails 4.5 to 1
  • 4.542225 grey #767676 on white: passes 4.5 to 1
  • 21 to 1 black on white, the top of the scale
  • 2.05 vs 4.54 grey #767676 on white without and with the gamma step
Read the full guide Fold the guide 6 min · 15 sources

Take two greys, #767676 and #777777, and put each on a white page. To the eye they are the same colour. To the guidelines they are on opposite sides of a line. The first reaches a contrast ratio of 4.542225 and meets the 4.5 to 1 level for ordinary text. The second reaches 4.478089 and does not.

That one step in an 8-bit channel is the whole argument of this essay. A contrast check is not a taste test. It is arithmetic with a hard edge, and the edge is where mistakes happen: a rounded number, a missing step in the formula, the wrong threshold for large text.

What the number measures

The Web Content Accessibility Guidelines define the contrast ratio as the relative luminance of the lighter colour plus 0.05, divided by the relative luminance of the darker colour plus 0.05. The guidelines add that such ratios run from 1 to 21, usually written 1:1 to 21:1. The 0.05 terms do two quiet jobs. They keep the division finite when the darker colour is black, whose luminance is zero. They also fix the top of the scale: black on white is 1.05 divided by 0.05, exactly 21.

Relative luminance is a measure of brightness normalised so that the darkest black is 0 and the lightest white is 1. It is not the same thing as the contrast ratio of a display, which is a separate idea. That older meaning compares the brightest and darkest shade a screen can produce, and the two share a name only by accident. For the sRGB colour space the luminance is a weighted sum: 0.2126 of the red, 0.7152 of the green and 0.0722 of the blue. Wikipedia’s article on relative luminance notes that green dominates because it is the major component of the light people perceive, with blue the smallest.

The step a chatbot forgets

Those weights apply to linear light, not to the numbers in a hex code. A colour on the web is stored as an 8-bit value per channel, and that value is gamma encoded. Wikipedia’s article on gamma correction explains why: encoding takes advantage of the non-linear way people see brightness, which is more sensitive to differences between dark tones than between light ones. So the first job is to undo the encoding. Divide each 8-bit value by 255. If the result is 0.04045 or less, divide it by 12.92. Otherwise add 0.055, divide by 1.055 and raise the answer to the power 2.4. Only then apply the weights.

The straight segment near black has a reason. The sRGB article points out that without it, the darkest twenty or so levels in an 8-bit image would map to extremely tiny changes in linear light. In practice the segment covers levels 0 to 10, because 10 divided by 255 is below 0.04045 and 11 divided by 255 is above it. W3C changed that cut-off in May 2021 from 0.03928, the value from an older version of the specification, to 0.04045. The definition says the change has no practical effect on the calculations. It is easy to confirm: computed over all 256 levels, both cut-offs produce identical linear values, because no 8-bit level falls between them.

Skipping the whole step is another matter. Treat #767676 as simple fractions of 255 and the ratio against white comes out near 2.05 instead of 4.54. A tool or a person that computes luminance without the gamma step will call a failing pair a pass, or the reverse, by a wide margin.

A worked example you can repeat

Start with the grey #777777. Each channel is 119, so c = 119 / 255 = 0.466667. That is above 0.04045, so the linear value is ((0.466667 + 0.055) / 1.055) to the power 2.4, which is 0.184475. All three channels agree, and the weights add to 1, so the luminance is 0.184475. White has luminance 1. The ratio is (1 + 0.05) divided by (0.184475 + 0.05), which is 1.05 divided by 0.234475, or 4.478089. That is below 4.5, so the pair fails the AA level for normal text.

Now step the grey down by one level to 118. The linear value falls to 0.181164 and the ratio rises to 4.542225. The pair passes. Scan all 256 greys on white and the lightest one that passes is #767676. Nothing lighter can pass, and that includes every tint of any hue that has the same lightness. Colour does not rescue this. Pure red on white has a luminance of 0.2126, exactly the red weight, and a ratio of 3.9985. It looks emphatic and still fails 4.5. Pure blue on white reaches 8.5925, and pure green on white only 1.3722.

Which level asks for what

Success criterion 1.4.3 sets the AA level for text at 4.5 to 1, relaxed to 3 to 1 for large text. Criterion 1.4.6 sets the AAA level at 7 to 1, relaxed to 4.5 to 1 for large text. Wikipedia’s overview of the guidelines describes the three conformance levels as A, AA and AAA.

Large text has a definition rather than a feeling. The guidelines call it large scale text: at least 18 point, or at least 14 point bold, or an equivalent size for Chinese, Japanese and Korean fonts. The W3C explanation converts those to roughly 24 and 18.5 CSS pixels. Technique G18 covers the 4.5 to 1 ratio for text and G17 the 7 to 1 ratio.

The numbers have a stated rationale. The explanation for 1.4.3 starts from 3 to 1 as the minimum for typical observers and multiplies by a factor of about 1.5 for people with roughly 20/40 vision, which gives 4.5 to 1. The same logic for roughly 20/80 vision gives about 7 to 1. Interface parts have their own rule. Criterion 1.4.11 asks for at least 3 to 1 against adjacent colours for the visual information needed to identify controls and states, and for the parts of graphics needed to understand them. Inactive components are exempt, and a change of state does not have to contrast with the previous state when the two never appear side by side.

Why you may not round up

The ratio 4.478089 is conventionally written to two decimals as 4.48. That is fine, because 4.48 is still below 4.5. The danger lies in rounding that crosses a threshold.

Round 4.478089 to one decimal and it becomes 4.5, which reads as a pass. The W3C explanation of 1.4.3 closes the gap directly: the ratios are thresholds, the computed values should not be rounded, and 4.499 to 1 would not meet 4.5 to 1. A display therefore has two honest choices. It can show enough digits that the user can see the shortfall, or it can cut rather than round when the nearest hundredth would reach a level the exact value has not. The verdict itself must come from the exact value, never from the printed one.

Exactness is also a question of arithmetic. Binary floating point stores most decimal fractions approximately, and Python’s documentation for its decimal module shows the visible symptom: 0.1 added three times, less 0.3, is exactly zero in decimal and a tiny nonzero number in binary. For a verdict at a boundary, decimal arithmetic with many digits removes any doubt about which side a ratio lies on.

What a ratio cannot tell you

A passing ratio is one test among many. The W3C explanation warns that anti-aliasing and thin or unusual fonts can render text much fainter than its defined colour, so the specified colours are the thing measured, not the picture on a screen. Size, weight, spacing and the actual font all matter and none of them appear in the formula.

Colour vision is a separate question. The explanation for 1.4.3 notes that colour deficiencies are so diverse that prescribing general colour pairs from quantitative data is not feasible, and that hues are perceived differently by people with such deficiencies. A pair with a good luminance ratio can still be hard to tell apart in a chart that relies on hue alone.

Nor does the ratio establish legal compliance. Exceptions apply to incidental text, pure decoration and logotypes, and which rules bind a given site is a matter for that site, not for a calculator. Transparency needs a decision too. A colour with partial opacity has no luminance of its own until it is mixed with what lies beneath it, so a checker has to composite it over the background first and say that it did.

Treat the result as a measured fact about two colours: an exact luminance for each, an exact ratio, and a clear pass or fail against each level. It is a firm floor for one part of accessibility, not the whole of it.

Sources

Every source consulted for this guide. Links checked November 9, 2026.

  1. Web Content Accessibility Guidelines (WCAG) 2.2 W3C
  2. Understanding Success Criterion 1.4.3: Contrast (Minimum) W3C Web Accessibility Initiative
  3. Understanding Success Criterion 1.4.6: Contrast (Enhanced) W3C Web Accessibility Initiative
  4. Understanding Success Criterion 1.4.11: Non-text Contrast W3C Web Accessibility Initiative
  5. G18: Ensuring that a contrast ratio of at least 4.5:1 exists between text (and images of text) and background behind the text W3C Web Accessibility Initiative
  6. G17: Ensuring that a contrast ratio of at least 7:1 exists between text (and images of text) and background behind the text W3C Web Accessibility Initiative
  7. CSS Color Module Level 4 W3C
  8. Relative luminance Wikipedia
  9. sRGB - Wikipedia Wikipedia
  10. Gamma correction Wikipedia
  11. Contrast ratio Wikipedia
  12. Web Content Accessibility Guidelines Wikipedia
  13. <color> CSS type MDN Web Docs
  14. Web Workers API MDN Web Docs
  15. decimal - Decimal fixed-point and floating-point arithmetic Python Software Foundation documentation