Skip to content
Hex Color Picker

Blog

Hex, RGB, HSL and CMYK Explained: Which Color Format Should You Use?

By the Hex Color Picker Team. Published . 10 minute read.

Hex, RGB, HSL and CMYK are four ways of writing down the same thing: a color. Hex and RGB describe a color by how much red, green and blue light it contains. HSL describes it the way people tend to think about it, as a hue, how vivid it is and how light it is. CMYK describes it as the amounts of four inks on paper. The first three are for screens, and the last one is for print.

For web work, use hex or RGB to store exact colors and HSL when you need to adjust them. For anything going to a printer, use CMYK, but treat the numbers as a starting point and confirm them with a proof. The rest of this guide explains why, with worked examples you can check yourself.

Throughout, we use one example color: dodgerblue, a bright blue that CSS defines as #1E90FF. In each format it looks like this:

FormatDodgerblueDescribes the color as
Hex#1E90FFRed, green and blue amounts in base 16
RGBrgb(30, 144, 255)Red, green and blue amounts from 0 to 255
HSLhsl(210, 100%, 56%)Hue angle, saturation and lightness
CMYKcmyk(88%, 44%, 0%, 0%)Percentages of cyan, magenta, yellow and black ink

You can paste any of these into the hex color picker and watch the other three update. Every number in this guide was produced with the same conversion code that powers the tools on this site.

RGB: mixing light

Screens make color by mixing red, green and blue light. Each pixel has three tiny lights, and the strength of each is stored as a number from 0 (off) to 255 (full). Eight bits per channel give 256 steps each, and 256 x 256 x 256 gives 16,777,216 possible colors.

That is the whole idea, and it has some consequences that are worth knowing:

RGB is the native language of displays, which is why every other screen format ends up converted to it before anything appears. The RGB color picker lets you build a color by moving the three channels directly.

Hex: RGB in a compact form

A hex code is the same three RGB numbers, written in base 16 and joined together. Base 16 uses the digits 0 to 9 and then the letters A to F for 10 to 15. Two hex digits can hold 0 to 255, so each channel fits in exactly two characters, and the whole color fits in six.

Take #1E90FF and split it into pairs: 1E, 90 and FF. In base 16, 1E is 1 x 16 + 14 = 30, 90 is 9 x 16 + 0 = 144, and FF is 15 x 16 + 15 = 255. So #1E90FF is rgb(30, 144, 255), exactly the same color. Nothing is lost or rounded in either direction. The step-by-step method is covered in how hex color codes work, and the hex to RGB converter does it instantly.

Why does hex exist at all, if RGB says the same thing? Because it is short, easy to copy and impossible to mistype in the way rgb(30,144,255 can be. It is also the format designers and brand guidelines use by default. A few details:

HSL: color the way people think about it

HSL stands for hue, saturation and lightness. It arranges the same screen colors around a wheel instead of in a mix of three lights:

Dodgerblue is hsl(210, 100%, 56%): a hue 210 degrees around the wheel, which is a little past the pure blue at 240 toward cyan, fully saturated, and slightly lighter than the midpoint.

HSL is the most useful format for adjusting a color. If you want a hover state that is a bit darker, you lower the lightness and leave the other two numbers alone. If you want a pale background version of the same color, you raise the lightness. Doing the same in hex means working out three new channel values every time. See HSL for designers for how to build a whole scale this way, and the HSL color picker to try it.

HSL has a limit you should know about: its lightness number is geometric, not perceptual. Yellow and blue at 50% lightness, #FFFF00 and #0000FF, are equally light by HSL, but yellow looks far brighter. We come back to this below.

CMYK: mixing ink

Print works the other way around from a screen. Paper reflects light, and ink absorbs some of it. Mixing cyan, magenta and yellow inks removes red, green and blue light from the white of the paper, which is why printing is called subtractive. In theory equal amounts of all three should make black. In practice they make a muddy brown, so printers add a fourth ink, black, and the whole system is called CMYK. The K is usually explained as "key", the plate that carries the fine detail.

Each ink is a percentage from 0% to 100%. Dodgerblue in CMYK is cmyk(88%, 44%, 0%, 0%): a lot of cyan, some magenta, and no yellow or black.

CMYK has two properties that matter when you move colors between formats:

Because of this, any online converter, including the ones on this site, uses a simple standard formula with no profile. It gives you a sensible starting point, not a press-ready value. The full story is in RGB vs CMYK.

Browsers don't accept CMYK in CSS, so CMYK values are for print specifications and design tools, not for stylesheets.

How the formats convert

Hex and RGB are the same numbers in different notation, so they convert exactly. The others involve arithmetic, and some of it rounds.

RGB to HSL. Scale each channel to a value between 0 and 1. Take the largest and the smallest. Lightness is their average. Saturation compares their gap to the room the lightness leaves. Hue depends on which channel is largest and how the other two compare. For rgb(30, 144, 255) the largest is blue at 1 and the smallest is red at about 0.12, so lightness is about 56%, saturation is 100% and the hue lands at 210 degrees.

RGB to CMYK. Black is what is left after the brightest channel: K = 1 minus the largest channel. Each ink is then whatever is needed to reach the remaining color. For rgb(30, 144, 255), K is 0 because blue is at full strength, cyan is about 88% (red is low), magenta about 44%, and yellow 0%.

Three things to remember about converting:

  1. Hex to RGB and back is exact. No rounding.
  2. HSL and CMYK are normally shown as whole numbers. Converting a color to either and back can change a channel by one step, a difference too small to see. For example, #1E90FF converted to hsl(210, 100%, 56%) and back gives #1F8FFF. If you need the exact original, keep the hex code.
  3. RGB to CMYK is not reversible in a meaningful way. Different CMYK values can look the same, and the conversion ignores the printer's profile.

The converters on this site follow these rules: hex to HSL, HSL to hex, RGB to CMYK, and the rest of the set.

Which format to use for which job

Here is a simple decision table.

JobUseWhy
Storing a brand color in CSS or a design fileHexShort, exact and universal
Doing math on channels, or passing a color to canvas or image codeRGBPlain 0 to 255 numbers
Building hover states, tints, shades and themesHSLChange one number to lighten or darken
Briefing a printerCMYK, plus hexPrinter works in ink, but the hex shows intent
Checking text contrastRGB or hexThe contrast formula starts from RGB
Describing a color to a colleagueName and hex"Dodgerblue, #1E90FF" is unambiguous

A good habit on a project is to store colors as hex or as CSS variables, and to reach for HSL only when you need to adjust one. The guide to colors in CSS and HTML shows the syntax for each.

Where the formats mislead

Each format hides something.

Hex hides how the color feels. Swap two pairs in #1E90FF to get #FF901E and you go from a bright blue to a bright orange, yet nothing about the six characters warns you. With practice you learn to read the pairs, but it never becomes as intuitive as a hue angle.

HSL hides brightness. Here are the six main hues at 100% saturation and 50% lightness, and how each compares with white text on it (as a contrast ratio):

HSLHexContrast against white
hsl(60, 100%, 50%) yellow#FFFF001.07:1
hsl(180, 100%, 50%) cyan#00FFFF1.25:1
hsl(120, 100%, 50%) green#00FF001.37:1
hsl(300, 100%, 50%) magenta#FF00FF3.14:1
hsl(0, 100%, 50%) red#FF00004.00:1
hsl(240, 100%, 50%) blue#0000FF8.59:1

All six have the same lightness number, yet the contrast against white ranges from almost none to very high. So don't assume that a fixed lightness gives safe text. The color contrast guide explains how to check properly.

CMYK hides the printer. The same four numbers can look noticeably different on different paper and presses.

A reference table of common colors

Here are some well-known colors in all four formats. The values come straight from the conversion code.

ColorHexRGBHSLCMYK
Red#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)cmyk(0%, 100%, 100%, 0%)
Lime#00FF00rgb(0, 255, 0)hsl(120, 100%, 50%)cmyk(100%, 0%, 100%, 0%)
Blue#0000FFrgb(0, 0, 255)hsl(240, 100%, 50%)cmyk(100%, 100%, 0%, 0%)
Orange#FFA500rgb(255, 165, 0)hsl(39, 100%, 50%)cmyk(0%, 35%, 100%, 0%)
Dodgerblue#1E90FFrgb(30, 144, 255)hsl(210, 100%, 56%)cmyk(88%, 44%, 0%, 0%)
Silver#C0C0C0rgb(192, 192, 192)hsl(0, 0%, 75%)cmyk(0%, 0%, 0%, 25%)

You can look up many more on the named colors pages.

Common mistakes

Frequently asked questions

What is the difference between hex and RGB?

None in terms of color. Hex writes the same red, green and blue values in base 16, packed into one string. #1E90FF and rgb(30, 144, 255) are the same color, and converting between them loses nothing.

Is HSL better than RGB?

It's better for adjusting colors, because lightness and saturation are single numbers you can change. RGB is better when you need the raw channel values. Screens display RGB, so HSL is always converted to it in the end.

Why can't I use CMYK in CSS?

Browsers render to a screen, which works in RGB. CMYK depends on a physical print process and a color profile that a browser doesn't have, so CSS doesn't accept cmyk() values.

Which format should I give a developer?

Give them hex, plus the color name if you have one. If you want hover and pressed states, give them the HSL value too, or say how much lighter or darker each state should be.

Which format should I give a printer?

CMYK values, with the hex code alongside so they can see the intent, and ask which color profile they want. Request a physical proof before the full run.

Do all four formats describe the same set of colors?

No. Hex, RGB and HSL describe the same screen colors (called the sRGB range). CMYK describes what a given set of inks can print, which is a different range. They overlap a lot, but each has colors the other can't match.

Try it yourself

More guides