How HSL to HEX conversion works
To write an HSL colour as HEX you rebuild the red, green and blue channels. Saturation and lightness decide how far apart the brightest and dimmest channels are (the chroma), and the hue decides which channel is brightest and where the middle one sits. Then each channel is written in base 16.
- C = (1 − |2L − 1|) × S (chroma).
- X = C × (1 − |(H ÷ 60) mod 2 − 1|).
- m = L − C ÷ 2.
- Pick (R′, G′, B′) by hue sector: 0–60°: (C, X, 0); 60–120°: (X, C, 0); 120–180°: (0, C, X); 180–240°: (0, X, C); 240–300°: (X, 0, C); 300–360°: (C, 0, X).
- R = round((R′ + m) × 255), and likewise for G and B.
- Write each channel as two HEX digits.
Worked example: hsl(210, 70%, 50%) to HEX
Here is the converter's own calculation for hsl(210, 70%, 50%), step by step. The result, #2680D9, is exactly what the tool above shows for this input.
- Chroma C = (1 − |2 × 0.5 − 1|) × 0.7 = 0.7.
- X = 0.7 × (1 − |(210 ÷ 60) mod 2 − 1|) = 0.35.
- m = 0.5 − 0.7 ÷ 2 = 0.15.
- 210° is in the 180–240° sector, so (R′, G′, B′) = (0, X, C) = (0, 0.35, 0.7).
- Add m and multiply by 255: R = 38, G = 128, B = 217.
- Red 38 = 2 × 16 + 6 → 26; green 128 = 8 × 16 + 0 → 80; blue 217 = 13 × 16 + 9 → D9.
- Joined:
#2680D9.
The twelve pure hues in HSL and HEX
Full saturation, 50% lightness, every 30° around the wheel.
| Colour | HSL | HEX |
|---|---|---|
| 0° | hsl(0, 100%, 50%) | #FF0000 |
| 30° | hsl(30, 100%, 50%) | #FF8000 |
| 60° | hsl(60, 100%, 50%) | #FFFF00 |
| 90° | hsl(90, 100%, 50%) | #80FF00 |
| 120° | hsl(120, 100%, 50%) | #00FF00 |
| 150° | hsl(150, 100%, 50%) | #00FF80 |
| 180° | hsl(180, 100%, 50%) | #00FFFF |
| 210° | hsl(210, 100%, 50%) | #0080FF |
| 240° | hsl(240, 100%, 50%) | #0000FF |
| 270° | hsl(270, 100%, 50%) | #8000FF |
| 300° | hsl(300, 100%, 50%) | #FF00FF |
| 330° | hsl(330, 100%, 50%) | #FF0080 |
Precision test: every HSL value through the converter
Every HSL value turns into a valid HEX code, and converting that code back gives the same colour, so this direction never loses information (100% exact over all 3,672,360 whole-number HSL values). The catch is reach: those values produce only 2,037,745 distinct HEX codes, so whole-number HSL can't name most of the 16.7 million HEX colours.
Method: every whole-number HSL value, through the converter's own code and back, compared on the 0–255 scale (how we test).
| Measure | Result |
|---|---|
| HSL values tested | 3,672,360 |
| Distinct HEX results | 2,037,745 |
| Came back exactly | 100% |
| Largest change (0–255 levels) | 0 |
| Average change | 0 |
Last updated · Source: Pixohub exhaustive test of lib/color-math.ts
Where you'll use HSL to HEX
Exporting a palette you designed in HSL
Many teams design scales by stepping lightness in HSL, then export HEX for tools that don't accept hsl(), such as some email builders, older Android XML and many brand portals.
Picking evenly spaced hues
The table below walks the hue wheel in 30° steps at full saturation and 50% lightness, which gives the twelve pure hues used in most colour wheels.
Turning CSS into design-tool input
If a stylesheet uses hsl() and you need the same colour in Canva or a slide deck, HEX is the format every app accepts.
Common mistakes
- Treating hsl(360, …) as different from hsl(0, …): both are red; hue wraps around.
- Expecting L = 100% to give a light tint: it gives pure white whatever the hue and saturation.
- Rounding the intermediate R′, G′, B′ before adding m, which shifts the result by one level.
- Assuming every HEX code has a whole-number HSL twin: only about one in eight does.