Color Converter

Published Updated

Type a color in HEX, RGB, HSL or CMYK and the other three boxes update. HEX is exact, but whole-number HSL and CMYK bring back the same color for only about 11% and 13% of the 16.7 million RGB colors, so #123456 returns as #123354.

Round trips through rounding

Each format is computed from the same three RGB integers, so HEX never drifts. HSL and CMYK are rounded to whole numbers, and converting them back does not always return the start. Examples from the page's own functions in Google Chrome 156:

StartHSL shownBack from HSLCMYK shownBack from CMYK
#123456hsl(210, 65%, 20%)#123354cmyk(79%, 40%, 0%, 66%)#123457
#6495EDhsl(219, 79%, 66%)#6494EDcmyk(58%, 37%, 0%, 7%)#6495ED
#FF0080hsl(330, 100%, 50%)#FF0080cmyk(0%, 100%, 50%, 0%)#FF0080

Trying all 16,777,216 RGB colors, the return trip through HSL was exact for 10.6% and through CMYK for 12.7%. Both were exact for only 1.6%.

What each box accepts

CSS Color Level 4 allows hex colors of 3, 4, 6 or 8 digits. The page covers the first and third, plus the number forms:

TypedResult
#abc or abcrgb(170, 187, 204)
rgb(100 149 237) or 100,149,237rgb(100, 149, 237)
rgba(1,2,3,0.5)rgb(1, 2, 3); alpha ignored
hsl(-30, 50%, 50%)rgb(191, 64, 128); hue wraps around
rgb(300,0,0)Refused

Converting a color

  1. Step 1

    Edit any one of the four boxes

    The page starts on cornflower blue, rgb(100, 149, 237). An entry it cannot read is flagged, and the other boxes keep their last good values.

  2. Step 2

    Read the other three

    They are rewritten from the color you typed, using whole numbers. Your own box keeps the text exactly as you wrote it.

  3. Step 3

    Copy a value

    Each box has its own copy button. HEX comes out upper-case, such as #6495ED.

Next steps

Color conversion questions

Why is the hex I get from HSL a little off?

HSL is shown in whole degrees and whole percentages, which cannot name every RGB color. Starting from #123456, the page shows hsl(210, 65%, 20%), and typing that back gives #123354. Across all 16.7 million RGB colors the worst channel difference was 5.

Which value should I store?

HEX or RGB. Both are exact integers from 0 to 255 per channel. Treat HSL and CMYK as a way to look at a color, and keep the original if the exact value matters.

Why was my 8-digit hex rejected?

The page reads 3 or 6 hex digits, with or without a hash. CSS also allows 4 and 8 digits for a transparent color, but alpha is not supported here, so #aabbccdd and rgba() alpha are not understood.

What does rgb(100%, 0%, 0%) give?

Red. A number followed by a percent sign is read as a share of 255, so rgb(100%, 0%, 0%) returns rgb(255, 0, 0). A percentage above 100 is refused, and a plain number above 255 still is.

Is the CMYK value safe to give a printer?

Treat it as an estimate. The conversion is plain arithmetic from RGB, with no color profile, so a print shop working from a profile may get different numbers.

Can I type a color name?

No. A word such as red is refused. Use a hex code or numbers.

Related Tools