Color Converter (HEX, RGB, HSL, CMYK)

Convert HEX, RGB, HSL, HSV and CMYK colors and check contrast.

HEX, rgb(), hsl(), hsv(), cmyk() or a CSS color name.

A background or text color to check contrast against.

Examples

HEX

#0A6B6B

#0A6B6B is rgb(10, 107, 107).

HEX
#0A6B6B
RGB
rgb(10, 107, 107)
HSL
hsl(180, 82.9%, 22.9%)
HSV / HSB
hsv(180, 90.7%, 42%)
CMYK
cmyk(90.7%, 0%, 0%, 58%)

CMYK uses the simple formula from the CSS Color 5 spec, not a printer profile, so printed colors will differ.

Fix the highlighted field to update the result.

Contrast (WCAG 2.2)

Text on this color: white reads best (6.30:1).

Contrast ratio against each background
AgainstContrastNormal textLarge text
White (#FFFFFF)6.30:1AA passAAA pass
Black (#000000)3.32:1FailAA pass

Normal text needs 4.5:1 (AA) or 7:1 (AAA). Large text (18 pt, or 14 pt bold) and interface parts need 3:1 (AA); large text needs 4.5:1 for AAA. Ratios are rounded down.

How to use

  1. Type or paste a color in any format: #0A6B6B, rgb(10, 107, 107), hsl(180, 82.9%, 22.9%), cmyk(90.7%, 0%, 0%, 58%) or a name such as teal. You can also use the color picker.
  2. Read every format at once, with a live swatch. Tap Copy next to the one you need.
  3. Check the contrast table to see whether text on this color passes WCAG AA or AAA. Add a second color to test a specific pair.

Everything runs in your browser.

How the conversion works

All formats describe the same sRGB color:

  • HEX is the red, green and blue values (0–255) written as three pairs of hex digits.
  • HSL and HSV describe hue (0–360°), saturation and lightness or value, using the CSS Color 4 and Smith (1978) formulas.
  • CMYK uses the simple CSS Color 5 formula: K = 1 − max(R, G, B), then C = (1 − R − K) ÷ (1 − K), and so on. It is not a print profile.

Contrast follows WCAG 2.2: work out each color’s relative luminance L, then ratio = (L1 + 0.05) ÷ (L2 + 0.05), from 1:1 to 21:1.

Example

#FF5733 is rgb(255, 87, 51), hsl(10.6, 100%, 60%), hsv(10.6, 80%, 100%) and cmyk(0%, 65.9%, 80%, 0%).

Color On white On black Normal text on white
#FF5733 3.15:1 6.66:1 Fail (AA large only)
#0A6B6B 6.30:1 3.32:1 AA pass
teal (#008080) 4.77:1 4.39:1 AA pass
#767676 4.54:1 4.62:1 AA pass
#777777 4.47:1 4.68:1 Fail

Normal text needs 4.5:1 for AA and 7:1 for AAA. Large text (18 pt, or 14 pt bold) needs 3:1 and 4.5:1.

Rounding, transparency and color names
  • Rounding: HSL, HSV and CMYK are shown to one decimal place, which converts back to the same HEX for every color. Contrast ratios are rounded down, because WCAG says 4.499:1 does not meet 4.5:1.
  • Transparency: 4- and 8-digit HEX and rgba() keep their alpha. Contrast is then measured after blending the color over each background.
  • Names: CSS has 148 color names for 139 distinct colors, because some are aliases, such as gray and grey.

Mixing colors by proportion, such as 3 parts blue to 1 part white? The ratio calculator scales the amounts.

Frequently asked questions

How do I convert HEX to RGB?

Split the six digits into three pairs and read each pair as a base-16 number. #FF5733 gives FF = 255, 57 = 87 and 33 = 51, so rgb(255, 87, 51).

What contrast ratio do I need for text?

WCAG AA needs at least 4.5:1 for normal text and 3:1 for large text. AAA needs 7:1 and 4.5:1. Large text is at least 18 pt, or 14 pt bold.

Is 4.49:1 close enough to pass?

No. WCAG says not to round the ratio, so even 4.499:1 fails the 4.5:1 test. We round displayed ratios down, so a failing color never shows as 4.50.

Why do CMYK values differ between converters?

Without a printer’s color profile there is no exact answer. Most web tools use the same simple formula, then round differently, so one color can show as 65.9%, 66% or 0.66.

What is the difference between HSL and HSV?

In HSL, 50% lightness gives the pure color and 100% gives white. In HSV (also called HSB), 100% value gives the pure color. Red is hsl(0, 100%, 50%) and hsv(0, 100%, 100%).

How many CSS color names are there?

CSS Color 4 lists 148 named colors, such as teal and rebeccapurple, plus the keyword transparent. Some are aliases, like gray and grey, so they cover 139 distinct colors.

Embed this calculator

Add this calculator to your own website for free. Copy the code below and paste it into your page’s HTML. The attribution link is optional.