Tools / Color Converter / HSL → HEX
HSL to HEX Converter.
HSL to HEX turns a human-friendly hue/saturation/lightness triple back into the six-digit string CSS and design tools expect. Internally it goes HSL → RGB → HEX; the interesting math is the HSL → RGB step, which reconstructs the three channels from the hue sector.
Not a recognizable HSL color.
All formats
The HSL → HEX formula
C = (1 − |2L−1|)·S, X = C·(1 − |(H/60 mod 2) − 1|), m = L − C/2. Pick the (R,G,B) ordering by hue sector, add m, scale to 0-255, then hex-encode.
Worked example
Convert hsl(220, 49%, 21%):
- C = (1 − |2·0.21 − 1|)·0.49 ≈ 0.20
- Hue 220° falls in the 180-240 sector → (0, X, C)
- Add m and scale → rgb(27, 42, 78)
- Hex-encode → #1B2A4E
JavaScript
// hslToRgb then rgbToHex (see colorConvert.ts)
hslToRgb({h:220,s:49,l:21}); // {r:27,g:42,b:78}
rgbToHex({r:27,g:42,b:78}); // "#1B2A4E" FAQ
Do I even need hex if CSS supports hsl()?
Modern CSS accepts hsl() directly, so for stylesheets you often don't. Hex is still required by many design tools, brand guidelines, and APIs that only accept a 6-digit string.