Sub topic 9
Check contrast and legibility
This chapter covers how to test the text and shapes in your series templates so people can read them on a phone, in sunlight, and with low vision. It assumes you already have a palette and type scale stored as tokens, as in the earlier chapters. It also assumes you can read a short Python script. Checking contrast is the last gate before the color and type decisions are frozen into templates.
Why check at the system level
You don't need to check every post. Check the token pairs once, record the results, and every graphic built from them inherits the result. That is the benefit of a system. If the text color and background color pass, every card that uses them passes. Only the exceptions need individual checks: photos behind text, accent colors on varying backgrounds, and small captions.
What contrast ratio measures
The WCAG (Web Content Accessibility Guidelines) contrast ratio compares the relative luminance of two colors. Relative luminance is a number from 0 (black) to 1 (white) that approximates how bright a color looks to the eye. The ratio runs from 1:1 (identical colors) to 21:1 (black on white).
The formula is (lighter + 0.05) / (darker + 0.05). Green counts most toward brightness and blue least, so a saturated blue and a saturated red can look different in hue yet have nearly the same luminance. Such a pair vibrates and is hard to read.
The thresholds
WCAG 2.x defines these minimums at level AA. They are the usual target for social graphics.
| Element | Minimum ratio | Notes |
|---|---|---|
| Normal text | 4.5:1 | Anything below the large-text size |
| Large text | 3:1 | At least 18 pt, or 14 pt bold (about 24 px, or about 18.7 px bold, at 96 dpi) |
| Icons and UI shapes needed to understand content | 3:1 | Arrows, chart lines, button outlines |
| Decorative elements | None | Only if removing them loses no meaning |
Level AAA asks for 7:1 for normal text and 4.5:1 for large text. It is a good goal for body copy in a graphic, because viewers rarely see it at full size.
The "points" in these thresholds assume a typical screen size. Your canvas is 1080 px wide but is shown at roughly 390 to 430 px wide on a phone. A 36 px body size is displayed at about 13 px, which is small. So pass the ratio check, then check size separately (see below).
Compute the ratio in code
This script expands the contrast function from the earlier tokens. It checks each pair and reports pass or fail. Run it with Python 3.
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)
TOKENS = {
"bg": "#10243e",
"text": "#ffffff",
"accent": "#ffb703",
"muted": "#6b7a90",
}
MINIMUM = {"normal": 4.5, "large": 3.0, "ui": 3.0}
PAIRS = [
("text", "bg", "normal"),
("accent", "bg", "large"),
("muted", "bg", "normal"),
("bg", "accent", "normal"),
]
for fg, bg, kind in PAIRS:
ratio = contrast_ratio(TOKENS[fg], TOKENS[bg])
status = "PASS" if ratio >= MINIMUM[kind] else "FAIL"
print(f"{fg:>6} on {bg:<6} {kind:<6} {ratio:5.2f}:1 {status}")White on the navy background gives about 15.6:1, and the amber accent on navy gives about 8.9:1. The muted gray is a typical trap. It looks fine next to the navy, but it falls under 4.5:1 and fails as caption text. Replace it with a lighter value and rerun the script. Keep this script with your design tokens and rerun it whenever a color changes.
Text on photos
Photos break the token check because the background is not one color. A caption can pass over the dark left half of a photo and fail over the bright sky on the right. Use one of these fixes, in order of preference:
- Place text on a solid panel or a scrim, which is a semi-transparent dark layer between photo and text. A scrim at 50 to 70 percent black is usually enough for white text.
- Keep the text in a fixed zone of the template, and pick or crop photos so that zone stays calm.
- Blur or darken the photo area behind the text.
Avoid thin outlines and drop shadows as the only fix. They help a little but do not reliably bring a failing pair up to 4.5:1.
To test a photo, check the lightest region under the text, not the average. Sample that region in your design tool's eyedropper, then run that hex value through the script as the background.
Legibility is more than ratio
A pair can pass the ratio test and still be hard to read. Review these factors too.
- Size on the phone. Minimum sizes for a 1080 px wide canvas: keep body text at 36 px or more, and avoid anything under 28 px even for credits. Preview the export at 400 px wide. If you must squint, enlarge it.
- Weight. Thin weights (100 to 300) lose strokes when scaled down and when placed on dark backgrounds. Use Regular (400) or heavier for body text and Medium or Bold for small text on color.
- Line length and spacing. Aim for roughly 30 to 45 characters per line in a graphic, and 1.2 to 1.5 line height. Tight lines of uppercase text are the hardest to read, so add letter spacing of a few percent to all-caps labels.
- Text length. A graphic that needs more than about 30 to 40 words is usually an article in disguise. Move the detail to the caption.
- Reversed text. Light text on a dark ground appears bolder and blurrier to some readers, especially with astigmatism. Use a slightly heavier weight and slightly looser spacing.
- Decorative typefaces. Script and display faces are acceptable for a short title, never for body text.
Do not rely on color alone
About 1 in 12 men and 1 in 200 women have some form of color vision deficiency. Red and green are the most commonly confused pair. If a chart legend or a status label uses only color to carry meaning, add a second cue: a label, a pattern, an icon, or a different shape. Test your palette with a color-blindness simulation. Figma plugins and the built-in view options in Photoshop and Illustrator do this. A grayscale preview is the quick check: if two colors look identical in grayscale, they differ only in hue and may collapse for some viewers.
Text in images and alt text
Screen readers cannot read text that is baked into an image. Most platforms let you add alt text to an image. Write alt text that includes the message, not just a description of the visuals. For a carousel, give each slide its own alt text. Put the essential message in the caption too, because captions are searchable and readable by everyone. Keep the on-image text short and treat the caption as the full record.
Limits of the WCAG ratio
The WCAG 2.x formula has known weaknesses. It treats light-on-dark and dark-on-light the same, although they read differently. It also ignores font weight and size beyond the two categories. A newer model called APCA (Accessible Perceptual Contrast Algorithm) addresses this and is proposed for WCAG 3, but WCAG 2.x remains the standard most guidelines and legal requirements cite. For a series, use WCAG 2.x as the pass or fail rule and treat your preview on a phone as the tiebreaker. When a pair passes the ratio but still looks weak, trust the preview and strengthen it.
Record results in the template
Add approved pairs to the template spec so that designers and tools can't drift from them. Extending the earlier JSON spec might look like this:
{
"template": "quote-card",
"approved_pairs": [
{ "fg": "#ffffff", "bg": "#10243e", "use": "headline, body" },
{ "fg": "#ffb703", "bg": "#10243e", "use": "large accents only" }
],
"min_body_size_px": 36,
"text_on_photo": "scrim at 60 percent black required"
}Common errors
- Checking the palette in isolation but not the accent on photos or on tinted panels.
- Using a brand color for small text because the logo uses it. Logos are exempt from WCAG contrast rules, but body text is not.
- Choosing the gray for captions last, when it is most likely to fail.
- Exporting a dark-mode variant of a graphic without rechecking the pairs.
- Passing 3:1 for large text and then shrinking that text in a smaller format. Recheck when you resize the canvas.
Exercise
A caption in your series uses #6b7a90 text on a #10243e background at 30 px. Name two ways to make it pass, and explain which threshold applies.
Show answer
At 30 px (about 22 pt), the caption is smaller than the large-text size of 24 px regular, so the normal-text threshold of 4.5:1 applies. The gray falls short of that. One fix is to lighten the text color until the script reports at least 4.5:1. Another is to enlarge the text to 24 px bold or larger, qualifying it as large text with a 3:1 minimum, though in practice lightening the color is better, since a small caption also needs to be legible on a phone. Rerun the script after either change, then preview at about 400 px wide.
Exercise
A quote card places white text over a photo of a bright sky. The token check for white on navy passed. Why is that not enough, and what should you do?
Show answer
The token check assumes the background is navy, but the text sits on the photo, whose lightest region may be close to white. Sample the lightest region under the text, run that hex through the contrast script, and expect a failure. Fix it with a semi-transparent dark scrim or a solid panel behind the text, or move the text to a calmer part of the image. Then recheck the contrast against the scrim-darkened color.