Hex to HSL Converter
WM-08Paste hex colors to get hsl() values, or switch to HSL to hex and paste hsl() colors to get hex codes. One color per line, both directions.
Runs in your browser. Nothing is uploaded.
Colors, one per line
Result
How to use it
- Paste one color per line. Use hex for Hex to HSL, or hsl() for HSL to hex.
- Click Hex to HSL or HSL to hex.
- Pick the comma or space style for hsl() output, or uppercase letters for hex output.
- Copy the result or download it.
Rounding you should know about
The result is written in whole degrees for hue and whole percent for saturation and lightness, so hsl(32, 100%, 50%) rather than a long decimal. Whole-number HSL can name fewer distinct colors than the 16.7 million that hex can, so converting a hex code to HSL and back can land on a slightly different hex. If you need the exact original, keep the hex. Use the HSL output when you want values that are easy to read and adjust by hand.
HSL to hex
The second action reads hsl() and hsla() in comma or space syntax, hue units of deg, grad, rad and turn, or a plain list such as 210 50 40 meaning degrees, percent, percent. Hue wraps around the circle, so -120 and 240 are the same, and saturation and lightness are clamped to 0 to 100. An alpha is kept and written as the last two hex digits of an 8-digit code. The result is rounded to whole RGB values.
Where HSL helps
Hue, saturation and lightness are easier to tweak than hex. Keep the hue and raise lightness to get a lighter version of the same color. CSS reads hsl() directly, so you can paste the result into a stylesheet. All the work happens in the browser and nothing is uploaded.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Line 1: hue "50%" must be an angle, not a percentage | The first value of hsl() is the hue, an angle, so it cannot be a percentage. | Write the hue as a number of degrees, for example hsl(50, 100%, 50%). |
Line 1: hsl() needs 3 values, plus an optional alpha, but has 2 | The hsl() function is missing a value. | Give hue, saturation and lightness. |
Questions people ask
How do I convert hex to HSL?
Turn the hex channels into numbers from 0 to 1, find the largest and smallest, and compute hue from which channel leads, lightness as their average and saturation from the spread. Pasting the hex code above does it and rounds to whole degrees and percent.
How do I convert HSL to hex?
Pick HSL to hex and paste hsl(210, 50%, 40%) or the plain numbers 210 50 40. You get #336699. The page converts to RGB first and then writes each channel as two hex digits.
Why does hex to HSL and back give a different hex?
The HSL output is rounded to whole degrees and percent, which loses some precision. Going back from the rounded values can land one step away on a channel. The page rounds on purpose to keep the values readable.
What is the difference between HSL and HSV?
Both use hue and saturation, but the third value differs. HSL lightness runs from black through the pure color to white, while HSV value runs from black to the pure color. CSS has hsl() and hwb() but no hsv() function. This site has a separate RGB to HSV page.
Does it accept hsla with transparency?
Yes. hsla(120, 100%, 25%, 0.5) is read with its alpha, and hex output gets an extra alpha pair, here #00800080. In the other direction, an 8-digit hex gives hsla() with the alpha as a decimal.
About this tool
Hex to HSL writes the hue in whole degrees and saturation and lightness in whole percent, so the result is rounded and is not guaranteed to turn back into the exact same hex. HSL to hex accepts hsl() and hsla() in comma or space syntax, hue units deg, grad, rad and turn, or a plain list like 210 50 40 (degrees, then percent, percent). Saturation and lightness outside 0 to 100 are clamped and hue wraps around 360. Alpha is carried through when the format can hold it (8-digit hex, rgba, hsla) and ignored by HSV and CMYK. Any other color format works as input too: hex, rgb(), hsl(), hsv(), cmyk() or a CSS color name.