Colour converter and WCAG contrast checker
This tool converts a colour between hex, RGB, and HSL with all three formats kept in sync, and checks WCAG 2.1 contrast between any two colours. It’s for developers and designers picking CSS colours and confirming text remains readable for accessibility compliance under WCAG 2.1 and the EU European Accessibility Act.
How it works
Conversion is pure maths: hex is parsed to RGB (3-digit shorthand is expanded by
doubling each digit), RGB maps to HSL via the standard max/min lightness formula,
and edits in any format propagate to the others. For contrast, each colour’s
relative luminance is computed by normalising the sRGB channels, gamma-
correcting them (values at or below 0.03928 divided by 12.92, otherwise raised to
the 2.4 power), and weighting them 0.2126·R + 0.7152·G + 0.0722·B. The ratio is
(lighter + 0.05) / (darker + 0.05), then compared against the WCAG thresholds.
Example
The default blue #3b82f6 is rgb(59, 130, 246) and hsl(217, 91%, 60%).
Against a white background its contrast ratio is about 3.7:1 — it passes AA
for large text (needs 3:1) but fails AA for normal body text (needs 4.5:1), so
you’d darken it for paragraph copy.
WCAG 2.1 thresholds
| Level | Normal text | Large text (18pt+/14pt+ bold) |
|---|---|---|
| AA | 4.5:1 | 3:1 |
| AAA | 7:1 | 4.5:1 |
All conversion and contrast maths run locally in your browser — nothing is uploaded.