How to Check Your Brand Color Against WCAG Contrast
Nov 19, 2026
The accent color on this blog is a warm terracotta red. It's used for links, tags, and the comment button. I like it a lot. It also turned out to be too light to pass the accessibility guidelines it should have been passing all along.
What WCAG Requires for Text Contrast
The WCAG contrast requirement compares the brightness of text against its background. Normal-size text needs a ratio of at least 4.5:1. Large text (24px, or about 19px bold) needs 3:1. Links and tags are usually normal-size text, so 4.5 is the number that matters for an accent color.
A JavaScript Function to Calculate Contrast Ratio
You don't need a tool for this. The formula is short enough to paste into a browser console or a Node script:
function luminance(hex) {
const [r, g, b] = hex.match(/\w\w/g).map((c) => {
const v = parseInt(c, 16) / 255;
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
});
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
function contrast(a, b) {
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return ((hi + 0.05) / (lo + 0.05)).toFixed(2);
}Pass it two six-digit hex colors, in either order: contrast('#c65445', '#f2f0e9').
Fixing a Brand Color That Fails
My accent was #c65445 on a cream background, #f2f0e9:
contrast('#c65445', '#f2f0e9') // 3.87
contrast('#fff6f0', '#c65445') // 4.14 (button text on the accent)Both under 4.5. Dark mode wasn't much better: the same red on the dark background, #101320, came in at 4.19.
The fix was to keep the hue and adjust the lightness until it passed. A slightly darker red for light mode, a slightly lighter one for dark mode:
contrast('#b54637', '#f2f0e9') // 4.73
contrast('#fff6f0', '#b54637') // 5.05
contrast('#d07164', '#101320') // 5.48If one accent color does double duty on light and dark backgrounds, check it against both. On this blog, the darker red that fixed light mode scored 3.43 on the dark background, worse than the original, which is why dark mode got its own shade.



Comments
Leave a Comment