How to Calculate Color Contrast Ratio (WCAG AA and AAA)

Last updated: · 5 min read

Light gray text can look elegant on a designer's monitor and be unreadable on a phone in sunlight, or for someone with low vision. The Web Content Accessibility Guidelines (WCAG) therefore replace “readable enough” with a number you can measure: the contrast ratio. It runs from 1:1 (two identical colors) to 21:1 (black on white) and is calculated from the relative luminance of the two colors. This guide walks through the formula, the AA and AAA thresholds, and the mistakes that most often lead to a wrong verdict. The outputs in the example come from the Color Contrast Checker tool.

Formula

1) Scale each channel (R, G, B) to 0–1: c = value ÷ 255
2) Linearize the channel:
   if c ≤ 0.04045:  c ÷ 12.92
   otherwise:  ((c + 0.055) ÷ 1.055) ^ 2.4
3) Relative luminance: L = 0.2126 × R + 0.7152 × G + 0.0722 × B
4) Contrast ratio = (L lighter + 0.05) ÷ (L darker + 0.05)

Thresholds:
  AA   normal text ≥ 4.5:1,  large text ≥ 3:1
  AAA  normal text ≥ 7:1,    large text ≥ 4.5:1
  UI components and graphics ≥ 3:1

The formula comes from the WCAG 2.x definitions of “relative luminance” and “contrast ratio”. The weights reflect how the eye responds: green contributes most to perceived brightness and blue least, which is why two colors that look equally dark can score very differently. The lighter color always goes on top of the fraction, so swapping text and background does not change the result. The text thresholds are set in Success Criteria 1.4.3 (AA) and 1.4.6 (AAA); the 3:1 threshold for non-text items such as button borders and icons comes from 1.4.11.

What the inputs mean

Text color
The color of the text or icon. Accepted formats are #rgb (for example #777), #rrggbb (#777777), rgb(119, 119, 119) and basic color names such as black, white, red or navy; case does not matter.
Background color
The color directly behind the text, in the same formats. Transparency (rgba, 8-digit hex) and hsl() are not supported; for a semi-transparent color, enter the solid color that results on screen.

Worked example: Gray #777777 text on a white background

  1. Input: text color #777777, background color #ffffff.
  2. For this gray all three channels are 119: 119 ÷ 255 = 0.4667. Linearized, ((0.4667 + 0.055) ÷ 1.055) ^ 2.4 ≈ 0.1845, and because the channels are equal the relative luminance is also 0.1845. White has a luminance of 1.
  3. Ratio = (1 + 0.05) ÷ (0.1845 + 0.05) = 1.05 ÷ 0.2345 ≈ 4.478. The tool shows two decimals: Contrast ratio: 4.48:1.
  4. 4.478 is below 4.5, so the tool reports AA — normal text (≥ 4.5:1): Fail. The same ratio is above 3, so it also reports AA — large text (≥ 3:1): Pass and UI components and graphics (≥ 3:1): Pass.
  5. Neither AAA line is met: AAA — normal text (≥ 7:1): Fail and AAA — large text (≥ 4.5:1): Fail.
  6. Darken the gray by one step to #767676 and the tool shows Contrast ratio: 4.54:1 with AA — normal text (≥ 4.5:1): Pass.

Result: On white, #777777 misses the AA threshold for normal text by a hair at 4.48:1, while #767676 passes at 4.54:1. That makes #767676 the lightest neutral gray that meets AA on a white background.

🌗 Color Contrast Checker (WCAG)

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

For most projects the practical target is level AA: 4.5:1 for body text and 3:1 for large text such as headings. AAA (7:1) makes sense for long-form reading and for audiences with low vision, but it is not expected of every component. “Large text” means at least 18 pt (24 px), or 14 pt bold (about 18.7 px); bold text at 16 px does not count. Logos, purely decorative elements and disabled controls are exempt from these criteria. Keep in mind that the ratio compares two flat colors only. Thin font weights, anti-aliasing and ambient light all affect legibility as well, so leave some margin instead of aiming exactly at the threshold.

Common mistakes

  • Rounding 4.48 up to 4.5. WCAG thresholds apply to the unrounded value, so a ratio that displays as 4.50:1 but is really 4.499 still fails. The tool bases its verdict on the unrounded ratio.
  • Checking body text only. Link colors, placeholder text, hover and focus states, error messages and button labels are subject to the same thresholds.
  • Entering a semi-transparent color as if it were solid. rgba(0, 0, 0, 0.6) is not a color on its own; work out the blended result (#666666 on white) and check that.
  • Measuring a single point of text placed over an image or gradient. Check the lightest and the darkest area the text crosses; the worst value decides.
  • Treating any bold text as “large text”. The 3:1 threshold applies to bold text only from 14 pt (about 18.7 px) upward.
  • Forgetting icons, form field borders and chart lines. They are not text, but they need at least 3:1 against the adjacent color.

Frequently asked questions

What contrast ratio does WCAG AA require?

At least 4.5:1 for normal text and at least 3:1 for large text (18 pt, or 14 pt bold, and larger). Non-text items such as button borders, icons and graphics also need 3:1.

Does #777 gray on white pass AA?

No. The ratio is 4.48:1, just under the 4.5:1 required for normal text; it passes for large text only. One step darker, #767676 passes at 4.54:1.

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

Not for the ratio. The lighter color always goes on top of the fraction, so white on blue and blue on white score the same (8.59:1 for white and #0000ff).

Did WCAG 2.2 change the contrast requirements?

No. The text criteria (1.4.3 and 1.4.6) are unchanged since WCAG 2.0, and non-text contrast (1.4.11) was added in WCAG 2.1. Older texts give the constant 0.04045 as 0.03928; for 8-bit colors both produce the same results.

What are the highest and lowest possible contrast ratios?

1:1 when both colors are identical and 21:1 for black against white. The tool shows 21.00:1 for #000 and #fff.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice