Skip to main content

Questions ยท Developer Tools ยท 2 min read

HEX, RGB, or HSL: Which Color Notation When?

They are three spellings of the same colours, so choose by task: HEX for design tokens and copy-paste compactness, RGB(A) when code computes channels or needs alpha, HSL when humans adjust hue, saturation, or lightness directly. Conversion between them is lossless.

HEX: the lingua franca of palettes

#3498db packs three bytes into six characters, survives every design tool, CSS version, and platform, and compares cleanly in diffs. Its opacity shorthand (#3498db80) covers translucent cases too. When the goal is communicating an exact colour, hex is the lowest-friction notation.

Its weakness is meaning: nothing about #e74c3c says "slightly darker red than #c0392b". Hex encodes machines-first, humans-second.

RGB: computation and alpha

rgb(52, 152, 219) exposes channels as numbers, which is what code wants: darkening by scaling values, blending by averaging, deriving greys by averaging channels. rgba() adds transparency with a 0-1 alpha, and modern CSS accepts slash syntax (rgb(52 152 219 / 0.5)).

Channel arithmetic still fights perception: naive darkening skews hues because eyes weight green most. For perceptually sane adjustments, HSL or a proper colour library beats raw RGB math.

HSL: colours as adjustable dials

hsl(206, 70%, 53%) names a hue (position on the colour wheel), saturation (vividness), and lightness. Design systems love it: one hue constant plus lightness steps generates accessible ramps; swapping hue re-themes the set. "Same colour but lighter" is one number in HSL and channel guesswork elsewhere.

Caveat: HSL lightness is mathematical, not perceptual; yellow at 50% looks far brighter than blue at 50%. Fine for consistent systems, imperfect for judging contrast; check ratios separately.

Worth knowing before you start

  • Conversion is exact among these three; nothing is lost translating hex to hsl and back.
  • For wide-gamut work, newer notations (oklch, display-p3) exist; sRGB-era hex/rgb/hsl remain the interoperable baseline.
  • Accessibility depends on contrast ratios, not notation; convert freely but always verify contrast.

Frequently asked questions

Is HSL better for performance?
No measurable difference; browsers convert everything internally anyway. Choose notation for readability and workflow, never speed.
How do I add transparency to a hex colour?
Append two hex digits for alpha: #3498db with 50% opacity becomes #3498db80. Or convert to rgb() with an alpha value; both render identically.
All questions โ†’
All guides โ†’
All articles โ†’