What to do next
- For any pair marked "Fails", use the button in the table to switch to a colour that passes. The hue stays the same and only the lightness moves. If you don't like the result, press "Undo".
- Under "Try other colour vision", switch to Protan, Deutan and Greyscale, and check that buttons and badges don't sink into the background.
- When you're done, press "Copy CSS variables". The colour for text on filled areas (white or not) is included.
The three colour roles
- Base: the colour of the background and margins. It covers the largest area.
- Main: the colour that gives the site or document its identity. It's used for the logo, header bands and main buttons.
- Accent: for the few places you really want people to look, such as a sign-up button or a "New" badge.
This tool also takes a text colour. Colour schemes are often talked about in threes, but what decides whether text can be read is how the text and the background pair up.
A split of "70% base, 25% main, 5% accent" is often quoted as a guide. Its original source couldn't be confirmed, though, so this tool doesn't impose it. Instead it counts how much of the sample each colour actually covers and shows that below the drawing. When you use more accent, check in the sample that the places you want to stand out still do.
What a contrast ratio is
It expresses the difference in lightness between two colours as a number from 1 to 21. A colour against itself is 1, and white against black is 21. WCAG 2.2, the international guideline for web accessibility, sets out how to calculate it and the standards for readability.
Contrast ratio = (luminance of the lighter + 0.05) ÷ (luminance of the darker + 0.05)Luminance is a lightness from 0 to 1, worked out from the strength of red, green and blue. Green counts the most and blue the least.
Here's what happens with grey text on white (luminance 1).
| Text colour | Luminance | Ratio to white | As body text |
|---|---|---|---|
| #000000 | 0 | 21:1 | Readable |
| #595959 | 0.1 | 7:1 | Readable |
| #767676 | 0.181 | 4.54:1 | Readable |
| #777777 | 0.184 | 4.47:1 | Not enough |
| #949494 | 0.296 | 3.03:1 | Not enough |
| #cccccc | 0.604 | 1.6:1 | Not enough |
#767676 and #777777 look almost identical, but they fall on either side of the 4.5:1 line. That's why this tool cuts the ratio off at two decimals rather than rounding it.
The standards
| Used for | Ratio needed | WCAG 2.2 criterion |
|---|---|---|
| Text at normal size | 4.5:1 | 1.4.3 Contrast (Minimum), Level AA |
| Large text | 3:1 | Same as above |
| Things that aren't text, such as button outlines, icons and charts | 3:1 | 1.4.11 Non-text Contrast, Level AA |
| Text at normal size (stricter standard) | 7:1 | 1.4.6 Contrast (Enhanced), Level AAA |
"Large text" means at least 18 points, or at least 14 points in bold. For scripts such as Japanese, an equivalent size is meant.
The five pairs this tool checks
Only the pairs actually layered on each other in the sample are checked.
- Text on base: body text. 4.5:1 or more.
- Main on base: links and headings written in the main colour. 4.5:1 or more. Bright main colours, such as yellow, fall short here. Then it's more practical to use the main colour only for filled areas, not for text.
- Accent on base: whether button and badge fills can be told apart from the background. 3:1 or more.
- Text on main-colour fills: text inside buttons and bands. 4.5:1 or more.
- Text on accent-colour fills: also 4.5:1 or more.
The colour of text on filled areas is picked automatically from white, the text colour and the base colour, whichever gives the highest ratio. The one picked appears in the "Pair" column of the table.
How a failing pair gets fixed
Pressing the button in the table keeps the hue and saturation, moves only the lightness, and switches to the nearest colour that meets the standard. When no lightness can get there (for example, against a colour of middling lightness), the other colour in the pair needs to change instead.
Trying other colour vision
People are born with different types of colour vision. According to Fukushima Prefecture's colour universal design guide, the most common type, called type C in Japan, accounts for about 95% of Japanese men and over 99% of women. The next most common are types D and P, which make red and green hard to tell apart.
The names type C, P, D and T were proposed by the Japanese NPO Color Universal Design Organization. In medical terms, type P is protan (first type) colour vision and type D is deutan (second type). This tool uses the English terms protan, deutan and tritan.
"Try other colour vision" recalculates the colours of the whole sample to show how hard they are to tell apart. It uses the conversion matrices (at severity 1.0) published by Machado and colleagues in 2009. As Sapporo City's guidelines also point out, conversions like this reproduce how hard colours are to distinguish, not the colours the person actually sees.
"Greyscale" removes colour and leaves only lightness. Whatever someone's colour vision, a scheme with differences in lightness is easier to tell apart. If the buttons and text still read in greyscale, that's a good sign.
Common mistakes
- Light grey text: it looks stylish, but #999999 on white is 2.84:1, which isn't enough for body text. Even small supporting text should reach 4.5:1.
- Using a brand colour as is for text: bright colours can work for filled areas but not for text. Prepare one darker colour of the same hue for text.
- Giving meaning through colour alone: marking required items only in red doesn't come across to people with protan or deutan vision. Add text or a symbol.
- Putting accents everywhere: the more places stand out, the less any of them do.
- Deciding on one screen only: a monitor in a bright room and a phone outdoors look different. Check schemes that only just pass on real devices too.
FAQ
- Are the colours I enter sent anywhere?
- No. The calculations and the sample drawings all happen inside your browser. The colours you enter are saved only in your browser.
- What is "Copy a link to this scheme"?
- It's a URL with the four colours added to the end. Opening it opens this page with the same scheme filled in, which is handy for showing a scheme to someone. Only the colour values go into the URL.
- Is 4.5:1 always readable?
- Not always. The contrast ratio only looks at the difference in lightness, not at how thin or small the text is or how well the colours go together. Give thin typefaces and small text some extra margin.
- Does a logo need 4.5:1 too?
- WCAG 2.2 excludes text that is part of a logo or brand name from the contrast criteria. This tool's results are meant for body text and text on buttons.
- How can I enter colours?
- It reads #1d3557, #abc, rgb(29, 53, 87), hsl(215 50% 23%), and plain numbers like "29, 53, 87". When you leave the field, the colour is rewritten as #rrggbb.
- Are the sample text and the shop real?
- No. They're made up so you can look at the colours.
Sources
- W3C, "Web Content Accessibility Guidelines (WCAG) 2.2" (the formulas for contrast ratio and luminance, criteria 1.4.3, 1.4.6 and 1.4.11, and the definition of large text)
- Machado, Oliveira, Fernandes, "A Physiologically-based Model for Simulation of Color Vision Deficiency" (IEEE Transactions on Visualization and Computer Graphics, 2009; the matrices used for the simulation)
- Fukushima Prefecture, "Color universal design guide" (in Japanese; the types of colour vision and their shares)
- Aichi Prefecture's colour universal design guidebook (in Japanese, PDF; the names type C, P and D and how they match the medical terms)
- Sapporo City, "Color universal design guidelines" (in Japanese, PDF; cautions about simulated images)