How HEX to HSL Converter works
This HEX to HSL converter turns a 3-digit or 6-digit hex code into the three numbers of the HSL model: hue as an angle from 0 to 360 degrees, saturation from 0% to 100% and lightness from 0% to 100%. The default #4f46e5 converts to hsl(243, 75%, 59%), and pure red #ff0000 is hsl(0, 100%, 50%). Values are rounded to whole numbers, which is how they are normally written in CSS. A Lightness shift slider adds or subtracts up to 40 points of lightness so you can derive a lighter or darker variant, and a four swatch ramp shows the same hue and saturation at 20%, 40%, 60% and 80% lightness.
Hex to HSL chart for common colors
HSL values as returned by the tool, rounded to whole numbers.
| Color | Hex | HSL | Hue | Saturation | Lightness |
|---|---|---|---|---|---|
| Black | #000000 | hsl(0, 0%, 0%) | 0 | 0% | 0% |
| White | #ffffff | hsl(0, 0%, 100%) | 0 | 0% | 100% |
| Gray | #808080 | hsl(0, 0%, 50%) | 0 | 0% | 50% |
| Silver | #c0c0c0 | hsl(0, 0%, 75%) | 0 | 0% | 75% |
| Red | #ff0000 | hsl(0, 100%, 50%) | 0 | 100% | 50% |
| Maroon | #800000 | hsl(0, 100%, 25%) | 0 | 100% | 25% |
| Brown | #a52a2a | hsl(0, 59%, 41%) | 0 | 59% | 41% |
| Tomato | #ff6347 | hsl(9, 100%, 64%) | 9 | 100% | 64% |
| Orange | #ffa500 | hsl(39, 100%, 50%) | 39 | 100% | 50% |
| Gold | #ffd700 | hsl(51, 100%, 50%) | 51 | 100% | 50% |
| Yellow | #ffff00 | hsl(60, 100%, 50%) | 60 | 100% | 50% |
| Olive | #808000 | hsl(60, 100%, 25%) | 60 | 100% | 25% |
| Beige | #f5f5dc | hsl(60, 56%, 91%) | 60 | 56% | 91% |
| Lime | #00ff00 | hsl(120, 100%, 50%) | 120 | 100% | 50% |
| Green | #008000 | hsl(120, 100%, 25%) | 120 | 100% | 25% |
| Turquoise | #40e0d0 | hsl(174, 72%, 56%) | 174 | 72% | 56% |
| Cyan | #00ffff | hsl(180, 100%, 50%) | 180 | 100% | 50% |
| Teal | #008080 | hsl(180, 100%, 25%) | 180 | 100% | 25% |
| Dodger blue | #1e90ff | hsl(210, 100%, 56%) | 210 | 100% | 56% |
| Blue | #0000ff | hsl(240, 100%, 50%) | 240 | 100% | 50% |
| Navy | #000080 | hsl(240, 100%, 25%) | 240 | 100% | 25% |
| Rebecca purple | #663399 | hsl(270, 50%, 40%) | 270 | 50% | 40% |
| Magenta | #ff00ff | hsl(300, 100%, 50%) | 300 | 100% | 50% |
| Purple | #800080 | hsl(300, 100%, 25%) | 300 | 100% | 25% |
| Pink | #ffc0cb | hsl(350, 100%, 88%) | 350 | 100% | 88% |
Black, white and grays have no hue. Their hue is reported as 0 and their saturation as 0%.
The hex to HSL formula
L = (max + min) / 2; S = (max - min) / (1 - |2L - 1|); H = 60 x ((G - B) / (max - min)) if red is largest, 60 x ((B - R) / (max - min) + 2) if green is largest, 60 x ((R - G) / (max - min) + 4) if blue is largest
R, G and B are the three hex pairs converted to decimal and divided by 255, and max and min are the largest and smallest of them. If max equals min the color is a gray, with saturation 0 and hue 0. A negative hue has 360 added. Worked example for #3b82f6: the pairs 3b, 82 and f6 are 59, 130 and 246, or 0.231, 0.510 and 0.965. Max is 0.965 and min is 0.231, so L = 0.598, which rounds to 60%. S = 0.734 / (1 - 0.196) = 0.913, or 91%. Blue is largest, so H = 60 x ((0.231 - 0.510) / 0.734 + 4) = 217 degrees. Result: hsl(217, 91%, 60%).
Lightening and darkening with the Lightness shift slider
The shift is added to the lightness value. Hue and saturation do not change.
A darker hover state
HEX colour #4f46e5, Lightness shift -10%
hsl(243, 75%, 49%), HEX #291fdb
A lighter variant
HEX colour #4f46e5, Lightness shift +10%
hsl(243, 75%, 69%), HEX #7b75eb
Red to light red
HEX colour #ff0000, Lightness shift +25%
hsl(0, 100%, 75%), HEX #ff8080
Maximum shift
HEX colour #4f46e5, Lightness shift +40% and then -40%
hsl(243, 75%, 99%), HEX #fbfbfe and hsl(243, 75%, 19%), HEX #100c55
Lightness is capped at 0% and 100%, so shifting white upward leaves it at hsl(0, 0%, 100%).
The ramp for one hue
HEX colour #ff0000
Lightness ramp: 20% #660000, 40% #cc0000, 60% #ff3333, 80% #ff9999
Hue angles on the color wheel
| Hue | Color at 100% saturation, 50% lightness | Hex |
|---|---|---|
| 0 (and 360) | Red | #ff0000 |
| 30 | Orange | #ff8000 |
| 60 | Yellow | #ffff00 |
| 120 | Green (lime) | #00ff00 |
| 180 | Cyan | #00ffff |
| 240 | Blue | #0000ff |
| 300 | Magenta | #ff00ff |
Adding 180 to a hue gives the complementary color. Hues wrap around, so 240 + 180 is 60.
Rounding: why the HEX row can differ from the code you typed
The converter rounds hue to a whole degree and saturation and lightness to a whole percent. There are more than 16.7 million hex colors but only about 3.6 million whole number HSL combinations, so several neighboring hex codes share one HSL value.
The HEX and RGB rows in the Values panel show the color rebuilt from those rounded HSL numbers, including any Lightness shift. With no shift they are usually identical to your input or a step or two off in a channel. Entering #4f46e5 gives hsl(243, 75%, 59%), and that HSL value written back as hex is #5048e5, rgb(80, 72, 229), where the original is rgb(79, 70, 229). The difference is invisible on screen, but if you need the exact original code, keep the one you typed. Colors whose HSL values are whole numbers to begin with, such as #ff0000, #663399 or #808080, come back unchanged.
When HSL is the better format to work in
- Hover, active and disabled states: keep hue and saturation, change lightness by 5 to 10 points.
- Comparing two colors: the hue shows at once whether a blue leans toward green (below 240) or toward purple (above 240).
- Diagnosing a dull color: the Saturation row shows how far it is from gray, where 0% is a pure gray and 100% is the most vivid color at that lightness.
- Theming with CSS variables: store the hue once and build surfaces, borders and text from it with different lightness values.
- Not for judging contrast: yellow and blue at the same HSL lightness differ hugely in perceived brightness, so check text pairs with a contrast checker.
Using HEX to HSL Converter
- 1
Type or paste a code into HEX colour, for example #3b82f6 or the short form #f00. The # sign is optional.
- 2
Read the HSL row in the Values panel for the full hsl() value, and the Hue, Saturation and Lightness rows for each number on its own.
- 3
Leave Lightness shift at 0% for a straight conversion, or drag it between -40% and +40% to darken or lighten the color.
- 4
Use the Lightness ramp swatches to see the hue at 20%, 40%, 60% and 80% lightness.