How to use the color converter
Edit any field and all the others update as you type:
- HEX: 3, 4, 6 or 8 hex digits, with or without the # sign. With 4 or 8 digits the last part is the alpha (transparency).
- Picker: choose a color visually with your system color picker.
- RGB: red, green and blue from 0 to 255.
- HSL: hue in degrees (0–360), saturation and lightness in percent.
- HSV / HSB: hue, saturation and value (brightness) in percent, as used by many design apps.
- Alpha: from 0 (fully transparent) to 1 (fully opaque).
The result card shows a preview with sample text in white and black, the CSS values ready to copy, and the contrast ratio against white and black. The details card lists every WCAG level as pass or fail.
How the conversions work
HEX is simply RGB written in base 16: each pair of digits is one channel from 00 to FF. HSL and HSV both describe the hue as an angle on the color wheel. HSL then measures lightness, where 50% is the pure color, 0% black and 100% white. HSV measures value, where 100% is the brightest version of the color.
RGB values are rounded to whole numbers, and HSL and HSV to one decimal place.
Contrast ratio
WCAG 2 first converts each color to its relative luminance, a number from 0 for black to 1 for white that follows how bright the eye perceives each channel. The contrast ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter color. It ranges from 1:1 to 21:1.
The thresholds are 4.5:1 for AA and 7:1 for AAA with normal text, and 3:1 for AA and 4.5:1 for AAA with large text (about 24 px, or 19 px bold). Interface parts such as icons and input borders need 3:1.
Worked example
Take #336699. In RGB that is 51, 102, 153. The largest channel (blue) gives a hue of 210°, and the result is hsl(210, 50%, 40%) or hsv(210, 66.7%, 60%).
Its relative luminance is about 0.125. Against white the ratio is 1.05 / 0.175 ≈ 5.99:1, so white text on this blue passes AA but not AAA. Against black it is only 3.50:1, enough for large text only.
Good to know
- Ratios are cut, not rounded, to two decimals, because WCAG does not allow rounding up: 4.499 fails AA.
- A transparent color is blended with each background before its contrast is measured.
- The picker cannot show transparency, so it displays the color as if it were fully opaque.