HEX vs RGB vs HSL: Which Color Format Should You Use?
All three formats represent the same colors — the difference is in readability, usability, and context. Here’s when to use each.
Side-by-Side Comparison
The same color in all three formats:
/* Indigo-500 */
color: #6366f1; /* HEX */
color: rgb(99, 102, 241); /* RGB */
color: hsl(239, 84%, 67%); /* HSL */
Convert between formats with our Color Converter.
HEX: Best for Design Handoff
Strengths:
- Universal — every tool understands HEX
- Compact — 7 characters for a full color
- Copy-paste from Figma, Sketch, Adobe XD
Weaknesses:
- Not human-readable —
#6366f1doesn’t intuitively convey “indigo” - Hard to adjust — making a color 10% lighter requires calculation
- Alpha channel is non-obvious —
#6366f180(50% opacity)
Use when: You’re copying colors from design tools, defining brand colors, or working with legacy CSS.
RGB: Best for JavaScript Calculations
Strengths:
- Easy math — interpolate between colors by adjusting 0-255 values
- Matches how screens work — direct red, green, blue channels
- Clear alpha —
rgb(99 102 241 / 50%)
Weaknesses:
- Not intuitive —
rgb(99, 102, 241)doesn’t suggest a hue - Hard to create variations — “make this 20% lighter” requires adjusting all three values
Use when: You need color math in JavaScript, generating dynamic colors, or working with canvas/WebGL.
// Mixing two colors in RGB
function mixColors(c1, c2, ratio) {
return {
r: Math.round(c1.r + (c2.r - c1.r) * ratio),
g: Math.round(c1.g + (c2.g - c1.g) * ratio),
b: Math.round(c1.b + (c2.b - c1.b) * ratio),
};
}
HSL: Best for Design Systems
Strengths:
- Human-intuitive —
hsl(239, 84%, 67%)= “a vivid color near blue, medium brightness” - Easy variations — change lightness from 67% to 90% for a lighter shade
- Perfect for theming — adjust hue to shift entire palette
Weaknesses:
- Not perceptually uniform — 50% lightness in yellow looks different than 50% in blue
- Less common in design tool exports
Use when: Building design tokens, creating shade scales, implementing dark mode, theming.
:root {
--brand-hue: 239;
--brand-50: hsl(var(--brand-hue), 84%, 95%);
--brand-100: hsl(var(--brand-hue), 84%, 90%);
--brand-500: hsl(var(--brand-hue), 84%, 67%);
--brand-900: hsl(var(--brand-hue), 84%, 20%);
}
By changing only --brand-hue, you shift the entire palette to a new color.
Recommendation
| Context | Use |
|---|---|
| Quick CSS styling | HEX |
| Design system / theme | HSL |
| JavaScript color manipulation | RGB |
| Future-proof design systems | OKLCH |
For most projects, use HSL for CSS custom properties (design tokens) and HEX for static values. This gives you the best of both worlds.
Generate harmonious palettes in any format with our Color Palette Generator.
This article is part of our CSS Color Systems Guide series.