How to Check Color Contrast for Accessibility
Learn how WCAG 2 contrast ratios work, which targets apply to text and controls, and how to fix color pairs that fail without starting over.
What the contrast ratio measures
A contrast ratio compares how light two colors are. It runs from 1:1, which is a color placed on itself, up to 21:1, which is pure black on pure white. WCAG 2, the web accessibility guidelines most sites are measured against, uses it to set minimums so people with low vision or color vision deficiencies can still read your text.
The lightness value behind the ratio is called relative luminance. In plain words, each red, green and blue channel is turned from its 0 to 255 value into an amount of actual light (screen values follow a curve, so this step straightens it out). The three amounts are then added with different weights: green counts the most, red less and blue very little, because human eyes are far more sensitive to green. The result is a number from 0 for black to 1 for white.
The ratio is (lighter luminance + 0.05) divided by (darker luminance + 0.05). The 0.05 on each side stands in for light reflecting off the screen. This is why a bright red and a bright blue can score poorly together: their luminance values are close even though their hues differ.
The WCAG 2 targets
- Level AA, normal text: at least 4.5:1.
- Level AA, large text: at least 3:1.
- Level AA, non-text parts such as input borders, focus outlines, icons that carry meaning and chart lines: at least 3:1 against the colors next to them.
- Level AAA, normal text: at least 7:1.
- Level AAA, large text: at least 4.5:1.
Large text means at least 18 point regular or 14 point bold. On the web, 18 pt is about 24 CSS pixels and 14 pt is about 18.66 CSS pixels, so 16 px bold body text is still normal text even though it looks heavy.
These are hard minimums, and the ratio must not be rounded up. Gray #777777 on white works out to about 4.48:1. Some tools display that as 4.5:1, but it fails AA for normal text. One step darker, #767676, reaches about 4.54:1 and passes. For AAA, #595959 on white sits right at about 7.00:1.
Which level you must meet depends on the policy, contract or regulation that covers your site, so check that document.
How to check a color pair
- Find the exact text and background colors. In a browser, right-click the element, choose Inspect and read the computed color values.
- If a value is in HSL, RGB or another format, convert it to hex with the color converter.
- Enter the foreground and background in the color contrast checker.
- Read the ratio and compare it with the target for that size and weight of text.
- Repeat for every pairing on the page: links, buttons, captions, form labels, error messages, footer text and badges.
- Keep the results in a short table so you can recheck them after the next design change.
Worked example for #777777 on white: each channel is 119, and 119 divided by 255 is about 0.467. Straightening the curve gives about 0.1845, and because all three channels are equal, that is also the luminance. White has a luminance of 1. The ratio is (1 + 0.05) divided by (0.1845 + 0.05), which is 1.05 divided by 0.2345, or about 4.48. Close, but below 4.5.
Fixing pairs that fail
The quickest fix is usually a change in lightness, not hue. Darken text that sits on a light background, or lighten text on a dark background, a few steps at a time and recheck after each step. Keeping the same hue means the color still reads as your brand color.
Many brand palettes include a bright accent that cannot reach 4.5:1 on white. Instead of dropping it, give it a job it can do: use it as a background behind dark text, reserve it for large headings where 3:1 is enough, or use it for decoration while a darker shade handles links and small text.
If you are building a palette from a logo or photo, pull the candidate colors with the image colour palette tool, then test each likely text and background pairing before you commit to it. Also avoid using color as the only signal: underline links in body text and pair error colors with an icon or message.
Text on images and gradients
A single background color makes checking easy. Photos and gradients do not, because the background changes behind each letter. Test against the worst case: for white text, sample the lightest area the text crosses; for dark text, sample the darkest.
On a gradient, check both ends of the area the text covers. On a hero image, remember that responsive layouts move text around, so a heading that sits on dark sky on a laptop may land on a pale building on a phone.
Reliable fixes include a solid or semi-transparent panel behind the text, a dark overlay across the whole image, or a subtle text shadow. For semi-transparent colors, check the final blended color you see on screen, not the raw value with its alpha channel.
States, exceptions and documents
Each interactive state needs its own check. Hover, focus, active and visited link colors are separate pairs, and a focus outline needs 3:1 against the colors around it. Placeholder text inside form fields is still text a person may need to read, so test it against the field background.
Some things are exempt from the WCAG 2 contrast minimums: logos and text that is part of a brand name, inactive (disabled) controls, and text or graphics that are purely decorative. Disabled buttons should still look clearly unavailable, but they do not need to hit 4.5:1.
If your site has a dark theme, test it as a separate set of pairs. The same checks apply to slides and PDFs: when you need to adjust a document after it is exported, see how to edit a PDF for free.
Common questions
Can I round 4.48:1 up to 4.5:1?
No. WCAG 2 thresholds are minimums, so a ratio of 4.48:1 fails the 4.5:1 requirement even if a tool shows it rounded to one decimal place.
Is 16 px bold text large text?
No. Bold text counts as large from 14 point, which is about 18.66 CSS pixels. Text at 16 px bold needs 4.5:1 for AA.
Do disabled buttons need to meet contrast minimums?
WCAG 2 exempts inactive user interface components from the contrast requirements. Once the control becomes active, its text and borders must meet the normal targets.
Last updated: