How to use the Color Converter (HEX, RGB, HSL)
- Type a color such as #1d4ed8, rgb(29, 78, 216) or hsl(224, 76%, 48%), or choose one with the picker.
- Click Copy next to the format you need. Colors with transparency are shown as 8-digit HEX, rgba() and hsla().
- In the contrast section, set the background color. The ratio and the WCAG pass or fail results update at once.
- Adjust the lightness (the last HSL value) until the contrast is high enough for your text size.
HEX, RGB and HSL
RGB describes a color as red, green and blue intensities from 0 to 255. HEX is the same three numbers in base 16 with two digits each, so #1d4ed8 means red 29, green 78 and blue 216. A short form like #fff repeats each digit and means #ffffff.
HSL describes the same color as hue (an angle on the color wheel from 0 to 360), saturation (0% grey to 100% vivid) and lightness (0% black to 100% white). It is easier to reason about: to make a color darker you lower the lightness, to mute it you lower the saturation. HSL values are rounded to whole numbers here, so converting back can differ by one in RGB.
Contrast and accessibility
WCAG 2.x defines contrast as (L1 + 0.05) / (L2 + 0.05), where L is the relative luminance of the lighter and darker color. Black on white is 21:1. Level AA asks for at least 4.5:1 for normal text and 3:1 for large text (about 24 px, or 19 px bold). Level AAA asks for 7:1 and 4.5:1.
Contrast is only part of readability. Font size, weight and the surrounding context matter too, and the ratio of a color with transparency depends on what is behind it, so the checker uses the solid color.
Frequently asked questions
How do I convert HEX to RGB?
Split the six digits into pairs and convert each pair from base 16 to decimal. For #1d4ed8 that gives 1d = 29, 4e = 78 and d8 = 216, so rgb(29, 78, 216). Paste the HEX value here and the RGB value appears immediately.
What is an 8-digit HEX color?
The last two digits are the alpha (opacity), from 00 transparent to ff opaque. #00000080 is black at about 50% opacity. It is supported by current browsers in CSS.
Why does converting HSL back to RGB change a value by one?
HSL is shown with whole numbers. Rounding hue, saturation and lightness loses a little precision, so a round trip can be off by one step in some channels.
What contrast ratio do I need?
At least 4.5:1 for normal body text and 3:1 for large text to meet WCAG AA. WCAG AAA needs 7:1 for normal text.
Are color names like "blue" supported?
Not at the moment. Use HEX, rgb() or hsl() notation.