HEX vs RGB vs HSL: Color Codes Explained

Updated · 2 min read

#FF5733, rgb(255, 87, 51) and hsl(11, 100%, 60%) are the same color written three ways. Each format exists for a reason, and knowing them makes color work much easier.

RGB: how screens make color

Screens mix red, green and blue light. Each channel goes from 0 (off) to 255 (full brightness):

  • rgb(0, 0, 0) is black, all lights off;
  • rgb(255, 255, 255) is white, all lights at full;
  • rgb(255, 87, 51) is strong red, some green, a little blue: a warm orange-red.

Modern CSS also accepts a space-separated form with opacity: rgb(255 87 51 / 50%).

HEX: RGB in compact form

A HEX code is the same three RGB numbers written in base 16 (hexadecimal), two digits each: #RRGGBB.

  • FF = 255, 57 = 87, 33 = 51, so #FF5733 = rgb(255, 87, 51).
  • Short form: #F53 means #FF5533; each digit is doubled.
  • With transparency: an extra pair sets alpha: #FF573380 is about 50% opaque.

To convert by hand, multiply the first digit by 16 and add the second (with A=10 … F=15). For 57: 5×16 + 7 = 87. Or just paste any code into the color converter.

HSL: the human-friendly format

HSL describes color the way people think about it:

  • Hue (0-360°): the position on the color wheel. 0 is red, 120 green, 240 blue.
  • Saturation (0-100%): from gray to fully vivid.
  • Lightness (0-100%): from black through the pure color at 50% to white.

This makes edits intuitive. For a darker hover state, lower the lightness: hsl(11, 100%, 60%) → hsl(11, 100%, 50%). For a matching color scheme, keep saturation and lightness and change the hue by 30° or 180°.

HSV / HSB

Used by color pickers in Photoshop and many design apps. Hue is the same as in HSL, but Value/Brightness at 100% gives the pure color, not white. The numbers differ from HSL even though the color is identical, so don't mix them up.

CMYK: for print

Printers mix cyan, magenta, yellow and black ink. Converting a screen color to CMYK with a formula gives a starting point, but the real printed result depends on the paper, ink and color profile. For important print jobs, ask your printer for a proof or use a Pantone reference.

Which one should you use?

SituationBest format
CSS, Figma, sharing a colorHEX: short and universal
Transparency in CSSRGB or HSL with alpha, or 8-digit HEX
Building shades and themes by handHSL
Design-app color pickersHSV/HSB
PrintCMYK (with a proof)

A note on newer CSS color spaces

Modern browsers also support oklch() and lab(). These are perceptually uniform: equal steps in lightness look equal, which HSL can't guarantee. Tailwind CSS v4 defines its default palette in OKLCH. HEX and RGB remain the most widely used and compatible formats.

Tools used in this guide

More guides