RGB vs HEX vs HSL

RGB, HEX and HSL all describe the same sRGB color space — but each format is optimized for a different kind of work. Here's what each is actually good at, and when to use which.

By COOLOUR Editorial Team Published Updated

The three formats at a glance

FormatExampleDimensionsBest for
HEX#267D70R, G, B (implicit)CSS, design handoff, documentation
RGBrgb(38, 125, 112)R, G, B (explicit)Alpha, programmatic manipulation
HSLhsl(170, 53%, 32%)Hue, saturation, lightnessPalette building, theming

RGB — how screens think

RGB is the native color model of screens. Every pixel on every display emits red, green and blue light at three levels — usually 8 bits each, for 256 levels per channel. RGB values describe those three levels directly.

Use RGB when:

  • You need alpha transparency — rgba(38, 125, 112, 0.5) is more readable than 8-digit HEX.
  • You're manipulating channels programmatically — darkening a color by multiplying each channel by 0.8 is trivial in RGB.
  • You're working with image data or canvas APIs, which natively use RGB.

Avoid RGB when:

  • You want to reason about color relationships (hue rotation, saturation) — HSL is easier.
  • You're writing compact documentation — HEX is more compact.

HEX — how CSS thinks

HEX is a compact notation for RGB. #267D70 and rgb(38, 125, 112) describe the same color — the HEX version is just shorter.

Use HEX when:

  • You're writing CSS or HTML and need compact notation.
  • You're documenting brand colors or design tokens.
  • You're working in design tools that default to HEX.

Avoid HEX when:

  • You need alpha and want it explicit — rgba() is clearer.
  • You're programmatically generating colors — RGB or HSL is more natural.

HSL — how designers think

HSL re-expresses RGB as hue, saturation and lightness. Hue is measured in degrees around the color wheel, saturation as a percentage from gray to pure, lightness as a percentage from black to white.

Use HSL when:

  • You're building palettes — changing only the lightness value produces a coherent tint or shade.
  • You're rotating hue for complementary, analogous or triadic schemes.
  • You're theming — hsl(var(--brand-h) 80% 40%) makes brand hue a variable.

Avoid HSL when:

  • You need perceptual lightness — HSL's lightness isn't perceptually uniform, so hsl(60, 100%, 50%) looks brighter than hsl(240, 100%, 50%) at the same lightness value.
  • You're doing exact color matching with an existing RGB or HEX value.

Conversion is exact

All three formats describe the same sRGB color space with 8 bits per channel, so conversion is exact and reversible for whole-number values. The only reason to worry about precision is when you're formatting to fewer decimal places, which can cause slight round-trip drift.

Practical recommendations

  • Store your brand tokens in HEX — it's the most universally understood format for design documentation.
  • Build your scale in HSL — reasoning about hue and lightness is easier than reasoning about three 0–255 values.
  • Export to RGB when the value crosses into code that needs explicit alpha.
  • Don't mix formats within the same concept — pick one representation per token and stick with it.

FAQ

Which color format is best?
There's no single best format. HEX is best for CSS documentation and handoff. RGB is best for alpha and programmatic work. HSL is best for palette building and theming.
Are RGB and HEX the same colors?
Yes. They describe the same sRGB color space — HEX is just a compact notation for the same three 8-bit channels.
Can HSL represent every color?
Yes, within the sRGB gamut. HSL is a lossless re-expression of RGB.
What about CMYK?
CMYK is a different model entirely — subtractive, for print. See CMYK Color Model for the full treatment.