What contrast ratio measures
The Web Content Accessibility Guidelines (WCAG) define contrast ratio as a number from 1:1 (no difference, such as white on white) to 21:1 (black on white). It compares the relative luminance, a measure of perceived brightness, of the two colours: (lighter + 0.05) ÷ (darker + 0.05).
Luminance is not the same as simple brightness. It weights green most and blue least, because that is how human eyes respond, and it applies a gamma correction to the colour values. That is why two colours that look equally "bright" on paper can have different contrast.
The thresholds
Large text means roughly 24 pixels, or 18.66 pixels if bold. Graphics that carry meaning, and the borders of input fields and buttons, need at least 3:1 against their surroundings. Pure decoration and disabled controls are exempt.
| Level | Normal text | Large text and UI components |
|---|---|---|
| AA (the common target) | 4.5:1 | 3:1 |
| AAA (enhanced) | 7:1 | 4.5:1 |
Real examples
The grey #767676 on white has a contrast of about 4.54:1, so it just passes AA for normal text. The only slightly lighter #777777 has about 4.48:1 and fails. A visible difference of one shade can mean the difference between compliant and non-compliant.
The light grey #999999 on white is only about 2.85:1, which fails for normal text and is too low for most borders. By contrast, a deep blue like #0B57D0 on white scores about 6.39:1 and passes AA comfortably, and black on white scores the maximum 21:1.
Pale grey placeholder text and light-on-light buttons are the usual offenders. Check them first.
How to choose accessible colours
- Start with your text and background colours and measure the ratio with a contrast checker.
- If a pair fails, darken the text (or lighten the background) slowly until it passes. Small changes in lightness are usually enough, so you can keep your brand hue.
- Test every state: hover, focus, disabled, visited links, text over images and error messages.
- Do not rely on colour alone to convey meaning. Add an icon, text or pattern, so people who cannot distinguish red from green still get the message.
- Check in both light and dark themes, because passing in one does not guarantee the other.
Text on images and gradients
Contrast is hardest when text sits on a photo. Put a semi-transparent dark panel behind the text, apply a gradient overlay, or place text in a plain area of the image. Then measure against the lightest part of the background the text will cross, not the average.
Beyond the ratio
- Font size and weight matter. Thin light fonts are harder to read at the same ratio.
- Pure black on pure white can feel harsh for some readers, so many designs use a very dark grey. That is fine as long as the ratio stays high.
- The WCAG 2 formula has known limits, and newer approaches are being developed, but the 4.5:1 and 3:1 targets remain the standard required by most laws and procurement rules.
- Always test with real people and real devices when you can.
Frequently asked questions
What contrast ratio do I need?
For WCAG AA, at least 4.5:1 for normal text and 3:1 for large text and interface components. For AAA, 7:1 and 4.5:1.
Does contrast matter for logos and decoration?
Logos and purely decorative elements are exempt from the text-contrast requirements, though clear contrast still helps recognition.
Why is my grey text failing even though it looks fine?
Monitors, brightness and eyes differ. Mid-greys on white often fall just under 4.5:1. Use a checker rather than judging by eye.
How is contrast calculated for transparent colours?
Calculate it after blending the colour with what is behind it. A semi-transparent colour has a different effective colour on each background.
Try these tools
Color Converter
Convert colours between HEX, RGB and HSL with a live preview and colour picker. Copy ready-to-use CSS values. Free web colour converter.
Open toolColor Picker from Image
Click any pixel of a photo to get its HEX and RGB colour, build a palette, and see the six dominant colours of the image. Runs in your browser, no upload.
Open toolCSS Gradient Generator
Build linear, radial and conic CSS gradients with up to five colour stops, angle and position controls, a live preview and copy-ready CSS code.
Open toolPX to REM Converter
Convert pixels to rem and em, and back, with a custom root font size. Includes a table of common sizes from 8px to 64px and a copy-ready CSS declaration.
Open toolKeep reading
How to verify web design files
How to verify web design files before you accept, publish or hand them off: check they arrived intact, nothing is missing, the code is valid, images are right and the build matches the design.
Read guideHow JSON Web Tokens work, and how to read one safely
Understand the three parts of a JSON Web Token, why the payload is readable by anyone, what the signature actually protects, and how to inspect a token without leaking it.
Read guideUnix timestamps explained: seconds, milliseconds and the Year 2038 problem
Learn what a Unix timestamp is, how to tell seconds from milliseconds, how to convert one to a human date, why time zones matter, and what the Year 2038 problem is.
Read guide