This free color contrast checker tests whether text is easy to read on its background. Enter two colours and you get the contrast ratio and the WCAG 2.2 results in one go, before the design reaches real users.
How to use the color contrast checker
- Enter the text colour as a hex code, such as
#595959, or choose it with the colour picker. - Enter the background colour in the same way.
- Read the contrast ratio, for example
4.54:1. The bigger the first number, the stronger the contrast. - Check the pass/fail results for normal text, large text and UI components and graphics, at level AA and AAA.
- Look at the live preview of normal and large text to judge the pair by eye. Press Swap to flip the two colours. The ratio stays the same, because the formula always compares the lighter colour with the darker one, but you can see how the pair looks in a light or a dark layout.
What the WCAG 2.2 thresholds mean
The Web Content Accessibility Guidelines (WCAG) 2.2 have three success criteria about contrast. This table shows the minimum ratio for each one.
| What you are checking | AA (minimum) | AAA (enhanced) |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text | 3:1 | 4.5:1 |
| UI components and graphical objects | 3:1 | No separate AAA level |
The text rules come from 1.4.3 Contrast (Minimum) and 1.4.6 Contrast (Enhanced). The 3:1 rule for non-text items comes from 1.4.11 Non-text Contrast. It covers what people need to see to find a control and know its state, such as the border of a text field, the tick in a checkbox or a focus ring. It also covers the parts of icons and charts that are needed to understand them.
What counts as large text?
WCAG defines large text as at least 18 point, or at least 14 point bold. One point is about 1.333 CSS pixels, so this works out to about 24px regular text, or about 18.5px bold text in W3C’s own rounding. Body copy is almost never large text, so use the 4.5:1 rule for paragraphs, labels and buttons.
Tip: Some items are exempt: logos and brand names, purely decorative text, and controls that are disabled. Disabled buttons still need to look clearly different from active ones, though.
How the contrast ratio is calculated
The ratio compares the relative luminance of the two colours, which is how bright each one looks, from 0 for black to 1 for white. The formula is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter colour. So results run from 1:1 (the same colour twice) up to 21:1 (black on white).
To get the luminance of an sRGB colour:
- Divide each red, green and blue value (0–255) by 255.
- Linearise each value: if it is 0.04045 or less, divide it by 12.92; otherwise use
((value + 0.055) / 1.055) ^ 2.4. The WCAG text prints the threshold as 0.03928, which W3C notes is an old figure. For normal 8-bit colours the result is the same. - Add them up with weights:
0.2126 × R + 0.7152 × G + 0.0722 × B.
Green carries most of the weight, because our eyes are most sensitive to it. That is why yellow and light green text on white fails so easily, while blue text often passes.
function luminance(hex) {
const [r, g, b] = [1, 3, 5].map(i => {
const c = parseInt(hex.slice(i, i + 2), 16) / 255;
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
});
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
function contrastRatio(a, b) {
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
}
console.log(contrastRatio('#767676', '#ffffff').toFixed(2)); // "4.54"Watch out: Never round a result up to make it pass. W3C says a ratio of 4.499:1 does not meet 4.5:1. For example, #767676 on white is 4.54:1 and passes AA, but #777777, just one step lighter, is 4.48:1 and fails.
Tips for choosing accessible colours
- Test brand colours early. Saffron
#ff9933on white is only 2.13:1, so it fails even for large text. Turn it round: dark navy text#1a1a2eon a saffron background is 8.01:1. - Light grey text is the most common failure. If you need muted text on white,
#595959gives about 7:1 and#767676is close to the 4.5:1 limit. - Check every state: hover, focus and visited links, and text placed over photos or gradients. For gradients and images, test the worst spot.
- Do not use colour alone to carry meaning. WCAG 1.4.1 asks for a second cue, such as an icon, an underline or text.
Learn more
- CSS Colors and Backgrounds
- Colour in UI Design
- Web Accessibility Basics: A Beginner’s Guide to WCAG 2.2
- Colour Theory for UI Designers: Practical Rules for Screens
- Dark Mode Design and CSS: From Colour Choices to a Working Toggle
- Colour Converter (HEX, RGB, HSL)
Frequently asked questions
Which level should I aim for, AA or AAA?
AA is the usual target for websites and apps: 4.5:1 for normal text, and 3:1 for large text and UI parts. AAA (7:1) is stricter. WCAG itself does not recommend requiring AAA for whole sites, because some content cannot meet every AAA criterion, but it is a good goal for long reading text.
Does it matter which colour is the text and which is the background?
Not for the ratio. The formula always puts the lighter colour on top, so swapping them gives the same number. The look changes, though, so check the preview.
Do placeholder text and icons need contrast too?
Icons that carry meaning, such as a search icon without a text label, are graphical objects and need 3:1. Placeholder text is still text, so treat it like any other text and aim for 4.5:1. Better still, use a visible label rather than a placeholder alone.
How do I check text on a gradient or photo?
Pick the colour of the lightest (or darkest) area behind the text and test that pair. If it fails, add a solid or semi-transparent overlay behind the text and test again.