Color Formats: Same Color, Different Notations
#3b82f6, rgb(59, 130, 246), and hsl(217, 91%, 60%) are all the same blue. Different formats exist because they're useful in different contexts.
The Three Main Formats
| Format | Example | Best For |
|---|---|---|
| HEX | #3b82f6 | CSS, design specs, compact notation |
| RGB | rgb(59, 130, 246) | Programmatic manipulation, canvas, SVG |
| HSL | hsl(217, 91%, 60%) | Creating color variations, design systems |
HEX — The Designer's Favorite
#3b82f6
│ ││ ││
│ ││ │└── Blue: f6 (246)
│ ││ └─── Blue: f6
│ │└──── Green: 82 (130)
│ └───── Green: 82
└──────── Red: 3b (59)
/* Shorthand (when pairs repeat) */
#fff → #ffffff
#333 → #333333
/* With alpha (transparency) */
#3b82f680 /* 50% transparent */RGB — The Machine's Format
rgb(59, 130, 246) /* opaque */
rgba(59, 130, 246, 0.5) /* 50% transparent */
/* Modern syntax (no commas) */
rgb(59 130 246)
rgb(59 130 246 / 0.5) /* with alpha */HSL — The Human's Format
HSL (Hue, Saturation, Lightness) maps to how humans think about color:
hsl(217, 91%, 60%)
│ │ │
│ │ └── Lightness: 60% (0%=black, 100%=white)
│ └────────── Saturation: 91% (0%=gray, 100%=vivid)
└─────────────── Hue: 217° (color wheel position)
/* Color wheel: 0°=red, 120°=green, 240°=blue, 360°=red */Why HSL is great for design systems:
/* Create shades of the same color by changing lightness */
--blue-100: hsl(217, 91%, 95%); /* very light */
--blue-300: hsl(217, 91%, 80%);
--blue-500: hsl(217, 91%, 60%); /* base */
--blue-700: hsl(217, 91%, 40%);
--blue-900: hsl(217, 91%, 20%); /* very dark */
/* Same hue, different saturation for muted variants */
--blue-muted: hsl(217, 30%, 60%);Conversion Formulas
// HEX to RGB
function hexToRgb(hex) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return { r, g, b };
}
// RGB to HEX
function rgbToHex(r, g, b) {
return '#' + [r, g, b]
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}Other Formats
| Format | Use Case |
|---|---|
oklch() | Perceptually uniform — new CSS standard, better for accessible palettes |
hwb() | Hue-Whiteness-Blackness — intuitive for mixing |
lab() | Device-independent, perceptually uniform |
| Named colors | rebeccapurple, tomato — 148 CSS named colors |
Convert colors: Color Converter — convert between HEX, RGB, HSL, and more instantly.