How to check the contrast of your text and background colours
Find the two colour values, put them in a contrast checker, read the ratio and decide what to change. A plain walk-through with free tools.
You need two colour values and a checker. That's the whole job. A free online tool does the arithmetic, and you only have to compare the result with the target.
Step 1: find the two colours
Web colours are usually written as hex codes. WebAIM shows a pale blue as rgb (97, 97, 255), or in hex as #6161FF, a "hexadecimal" format that's very common in web page styles.1 If your theme or page builder has a colour setting, the code is normally shown next to the swatch.
If you don't know the colours, the checker can find them for you. WebAIM's tool has an eyedropper in its colour picker, which extracts the colour value from any element on screen.2 Click the text, then click the background behind it.
Step 2: enter them in a checker
MDN points to WebAIM's Colour Contrast Checker for this.3 You enter a foreground and a background colour in hex form, or pick them with the colour picker.2 Foreground is the text. Background is whatever sits behind it.
The tool then shows the ratio. It gives AA and AAA results for normal text and large text. For graphical objects and user interface components it gives an AA result.2 The result is the same whichever colour you put in which box.
Browsers can do this as well. MDN notes you can check colour contrast on the fly with Firefox's developer tools.3 Other browsers have similar panels, so look for an accessibility or inspect option.
Step 3: read the result against your target
Decide the target before you look. Most body text needs 4.5 to 1, and large text needs 3 to 1.3 The full list is in the page on the ratios, and the size cut-offs are on the large text page.
A near miss still counts as a miss. A reading of 4.47 doesn't get rounded up to a pass.1
Step 4: fix what fails
Change one colour at a time. Most of the time it's easier to darken the text than to lighten the page. WebAIM points out that changing the lightness of a colour will change its contrast ratio against another colour.1 The checker has a lightness slider that adjusts the perceived lightness of the colour, so you can nudge it until the pass appears.2
Before you change a colour in your site's settings or stylesheet, write down the old value. That way you can go back if the new one looks wrong.
Things that fool a checker
Some situations don't give a clean answer:
- Transparency. Reducing the alpha of an element reduces its contrast, because the colour underneath shows through.1 Check the colour you actually see on screen, not the one in the settings.
- Photos and gradients. The ratio changes from one spot to the next. WebAIM recommends usually testing the area where contrast is lowest.1 Keeping text readable over photos and banners goes further.
- Hover and focus. Link and button colours can change in those states, and WebAIM says every state is measured separately.1 Hover over a link while you check it.
- Every page, not just the home page. Footers, sidebars and tinted boxes often use different backgrounds. A colour that passes on white may fail on a pale panel.
Checking a whole page at once
Doing this pair by pair gets slow on a big page. WebAIM says its WAVE tool can analyse the contrast ratios of all the page's text elements at once.2 A scan like that is a good first pass. Then use the checker for any pair that needs a closer look.
Cited material
- Contrast and Color Accessibility, WebAIM, Utah State University
- Contrast Checker, WebAIM, Utah State University
- Color contrast, MDN Web Docs, Mozilla