HEX, RGB, HSL and CMYK Color Codes Explained
HEX, RGB and HSL are three ways to write the same screen color. #3B82F6 in HEX is rgb(59, 130, 246) in RGB and hsl(217, 91%, 60%) in HSL. CMYK is used for print and describes ink rather than light, so screen-to-print conversions are approximate.
RGB
RGB mixes red, green and blue light, each from 0 to 255. rgb(0, 0, 0) is black and rgb(255, 255, 255) is white.
HEX
HEX writes the same three numbers in base 16, two digits each: #RRGGBB.
#3B82F6 splits into 3B, 82 and F6:
- 3B = 3 × 16 + 11 = 59
- 82 = 8 × 16 + 2 = 130
- F6 = 15 × 16 + 6 = 246
So #3B82F6 = rgb(59, 130, 246). The HEX to RGB converter and the RGB to HEX converter convert either way.
HSL
HSL describes a color the way people think about it:
- Hue: the position on the color wheel, 0 to 360 degrees (0 is red, 120 green, 240 blue).
- Saturation: how vivid it is, 0% gray to 100% full color.
- Lightness: 0% black, 50% the pure color, 100% white.
HSL makes it easy to create lighter or darker versions of a brand color: keep the hue and saturation and change only the lightness. The RGB to HSL converter gives hsl(217, 91%, 60%) for our example.
CMYK for print
Printers mix cyan, magenta, yellow and black ink. A simple conversion of rgb(59, 130, 246) gives about cmyk(76%, 47%, 0%, 4%), which the RGB to CMYK converter shows. Real print colors also depend on the printer, ink and paper, so designers use color profiles and test prints for anything important. Some bright screen colors cannot be printed exactly.
Which to use
| Use | Format |
|---|---|
| Website CSS | HEX, RGB or HSL (all work) |
| Building color palettes | HSL |
| Transparency | rgba() or hsla(), or 8 digit HEX |
| CMYK, checked with a proof |
Gradients
Once you have your colors, the CSS gradient generator blends two or more of them into CSS you can paste into a stylesheet.
Questions and answers
How do I convert HEX to RGB?
Split the code into three pairs and convert each from base 16 to base 10. #3B82F6 becomes 59, 130 and 246.
Why do printed colors look different from the screen?
Screens mix light and printers mix ink, which can show a smaller range of colors. Conversions to CMYK are approximate.