Color converter
Type a color as #hex, rgb(), or hsl(), or pick one, and the converter shows it in all three formats along with how readable white and black text are on it. It measures contrast with the WCAG 2 formula, where body text needs at least 4.5:1. It runs in your browser; nothing you enter is uploaded.
Hex, RGB, and HSL
All three describe the same sRGB color in different ways. #3366ff, rgb(51, 102, 255), and hsl(225, 100%, 60%) are the same blue:
- Hex writes the red, green, and blue amounts as two hexadecimal digits each, from
00toff. The short form#abcdoubles each digit, so it means#aabbcc. - RGB gives the same three amounts as numbers from 0 to 255.
- HSL gives a hue as an angle on the color wheel, with 0 for red, 120 for green, and 240 for blue, then saturation and lightness as percentages. It's the easiest of the three to adjust by hand: raise the lightness and you get a paler shade of the same color.
The converter rounds HSL values to whole numbers, so converting to HSL and back can move a color by one step. #6fd3a8 becomes hsl(154, 53%, 63%), and that HSL value comes back as #6fd3a7, a difference no one can see. When you need the exact color, copy the hex value.
How contrast is calculated
The WCAG 2 contrast ratio compares how bright two colors look, which WCAG calls relative luminance. The formula converts each channel from its sRGB value to linear light, then weights it by how sensitive the eye is to that color: luminance is 0.2126 × red + 0.7152 × green + 0.0722 × blue. The ratio is (lighter + 0.05) ÷ (darker + 0.05). It runs from 1:1 for two identical colors to 21:1 for black on white.
Green counts for most of the brightness, which is why light greens need dark text. The default color, #6fd3a8, has a ratio of 1.82:1 with white text and 11.56:1 with black, so put black text on it. Mid grays sit close to the line: #767676 on white is 4.54:1 and passes, while #777777, one step lighter, is 4.48:1 and fails.
Which level you need
- AA, success criterion 1.4.3: at least 4.5:1 for normal text and 3:1 for large text. WCAG counts text as large from 18 point, or 14 point bold, which is 24px, or about 18.7px bold, in CSS pixels.
- AAA, success criterion 1.4.6: at least 7:1 for normal text and 4.5:1 for large text.
- Since WCAG 2.1, criterion 1.4.11 also asks for 3:1 for icons, input borders, and other parts of the interface that people need to see.
Aim for 4.5:1 on all body text, whatever its size, and save the 3:1 large-text allowance for headings. AA is also the level that Section 508 in the US and the EN 301 549 standard in the EU require.
What the converter doesn't handle
- It can't read color names such as
rebeccapurple, or newer CSS formats such asoklch(),lab(), andhwb(). - It ignores transparency, so it reads
#3366ff80as#3366ff. The real contrast of a semi-transparent color depends on what's behind it, so check the color it ends up as on screen. - The ratio checks text against a flat background. For text over a photo or a gradient, check the contrast at the background's lightest and darkest points.