Sub topic 9
Check contrast and legibility
This chapter assumes you already have a color palette and a type scale recorded as tokens, and that you can place text over a background in your design tool. Here you will test whether people can actually read those choices.
Why contrast matters in a series
A series repeats the same color pairs in dozens of graphics, so one weak pair repeats just as often. Readers also view posts on small phones, in sunlight, and while scrolling fast. Checking each pair once, when you build the system, protects every later post.
The numbers to meet
The Web Content Accessibility Guidelines (WCAG) measure contrast as a ratio from 1:1 (no difference) to 21:1 (black on white).
| Text type | Minimum ratio |
|---|---|
| Normal text | 4.5:1 |
| Large text (about 24px regular or 19px bold and up on a web page) | 3:1 |
| Meaningful icons and shapes | 3:1 |
"Large" is relative to the final viewing size. On a 1080px-wide graphic shown at phone width, treat your 36px body text as normal text, not large text.
Compute the ratio
The script below uses the WCAG formula. It converts each color to relative luminance (perceived brightness), then compares the lighter and darker values.
def channel(c):
c = c / 255
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
def luminance(hex_color):
h = hex_color.lstrip('#')
r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4))
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
def contrast_ratio(a, b):
la, lb = luminance(a), luminance(b)
hi, lo = max(la, lb), min(la, lb)
return (hi + 0.05) / (lo + 0.05)
print(round(contrast_ratio('#ffffff', '#10243e'), 2))White on the navy #10243e gives about 15.6, far above 4.5. The yellow accent #ffb703 on the same navy comes out near 9, so it also passes for text.
Test every pairing in the palette
Do not test colors one at a time. Test each text-on-background pair your templates allow, and record the results.
- List every pairing: body text on background, accent on background, text on accent buttons.
- Run the ratio for each pair.
- Mark each as pass for normal text, pass for large text only, or fail.
- Remove or restrict failing pairs in the token set, for example by noting "accent only for headlines".
Legibility beyond the ratio
A passing ratio does not guarantee readable text. Check these as well:
- Text over photos. Contrast changes across the image. Add a solid overlay or a gradient scrim behind the text, then test against the lightest part of the image under the text.
- Thin weights and small sizes. Light fonts at small sizes blur on phone screens. Keep body text at or above your token minimum.
- Color alone. Do not use color as the only signal, such as red versus green for good versus bad. Add a label or icon.
- Line length and spacing. Short lines with generous line height read faster in a graphic.
Check it on a real screen
Export a graphic and view it on your phone at arm's length, then shrink it to thumbnail size on your computer. If the headline is still clear and the focal point survives, the graphic works. Grayscale preview is another fast test: if text vanishes without hue, the pair relies too much on color difference.
Exercise
Your template places 36px body text in #8a8a8a on a white background. The ratio computes to about 3.5:1. Does it pass, and what would you change?
Show answer
It fails. The text is normal size at the final viewing size, so it needs 4.5:1, and 3.5:1 only meets the large-text minimum. Darken the gray (for example toward #595959) and recompute until the ratio is at least 4.5, then update the text color token.