- Home
- Tools
- Color & Design
- Color Converter
- HEX to HSL Converter
HEX to HSL Converter
Turn a HEX color code into hue, saturation and lightness, with enough decimals to get the same code back.
With or without the #. Three digits work too.
In HSL
hsl(210, 50%, 40%)
Hue
210°Alpha
100%
In the other notations
Name
steelbluenearest CSS name, #4682b4
HEX to HSL by hand
The converter opens with #336699. This is how that color gets from HEX to HSL, step by step.
- Read the three pairs of
#336699as numbers in base 16, where the first digit counts sixteen times:33is 3 × 16 + 3 = 51,66is 6 × 16 + 6 = 102 and99is 9 × 16 + 9 = 153. Those are the red, green and blue values. - Divide each value by 255, so that it runs from 0 to 1: 51 ÷ 255 = 0.2, 102 ÷ 255 = 0.4 and 153 ÷ 255 = 0.6.
- The largest of the three is 0.6 and the smallest 0.2. Lightness is halfway between them: (0.6 + 0.2) ÷ 2 = 0.4, or 40%.
- Saturation is the gap between those two, 0.6 − 0.2 = 0.4, as a share of the most this lightness leaves room for, 1 − |2 × 0.4 − 1| = 0.8: 0.4 ÷ 0.8 = 0.5, or 50%.
- Blue is the largest, so the hue is 60° × ((red − green) ÷ gap + 4) = 60° × ((0.2 − 0.4) ÷ 0.4 + 4) = 210°.
- With one decimal at most:
hsl(210, 50%, 40%).
Well-known colors in HEX and HSL
| Color | HEX | HSL |
|---|---|---|
| black | #000000 | hsl(0, 0%, 0%) |
| white | #ffffff | hsl(0, 0%, 100%) |
| gray | #808080 | hsl(0, 0%, 50.2%) |
| red | #ff0000 | hsl(0, 100%, 50%) |
| orange | #ffa500 | hsl(38.8, 100%, 50%) |
| yellow | #ffff00 | hsl(60, 100%, 50%) |
| lime | #00ff00 | hsl(120, 100%, 50%) |
| green | #008000 | hsl(120, 100%, 25.1%) |
| cyan | #00ffff | hsl(180, 100%, 50%) |
| blue | #0000ff | hsl(240, 100%, 50%) |
| purple | #800080 | hsl(300, 100%, 25.1%) |
| magenta | #ff00ff | hsl(300, 100%, 50%) |
Why the result can have decimals
- This example comes out in round numbers; most colors do not.
#7c3aedishsl(262.1, 83.3%, 57.8%), and rounding that tohsl(262, 83%, 58%)gives#7c3bed, a different code. One decimal is enough to get the exact HEX code back for every color. - A gray has no hue. When the three pairs are equal, as in
#808080, the saturation is 0% and the hue is written as 0. - HSL lightness is not how light a color looks.
#ffff00and#0000ffboth have a lightness of 50%, and the yellow is far brighter to the eye.
The color converter shows a color in all seven notations at once, with a picker to choose it by eye.