HEX or RGB to HSL: Conversion Formula With Worked Examples
How to convert a HEX or RGB colour to HSL step by step: the hue, saturation and lightness formulas, two worked examples, a reference table and common mistakes.
The short answer
To convert HEX to HSL, first turn the HEX code into RGB, divide each value by 255, then find the largest and smallest of the three. Lightness is their average, saturation depends on how far apart they are, and hue depends on which channel is largest. The free Color Picker does this instantly: type a HEX code and it shows the HSL value, rounded to whole numbers, ready to copy.
What HSL means
HSL describes a colour the way people tend to think about it:
- Hue (H): the position on the colour wheel, from 0° to 360°. Red is 0°, green is 120°, blue is 240°.
- Saturation (S): how strong the colour is, from 0% (grey) to 100% (full colour).
- Lightness (L): from 0% (black) through 50% (the pure colour) to 100% (white).
That is why designers like it. To make a colour lighter, raise L. To make it more muted, lower S. To get a related colour, change H. Doing the same in HEX means changing three numbers at once.
Step 1: HEX to RGB
A HEX code is three pairs of base-16 digits: red, green, blue. #2E8B57 splits into 2E, 8B and 57, which are 46, 139 and 87 in decimal. If you need the details of that step, see HEX to RGB by hand.
Step 2: scale to 0–1
Divide each channel by 255:
- R = 46 ÷ 255 = 0.1804
- G = 139 ÷ 255 = 0.5451
- B = 87 ÷ 255 = 0.3412
Step 3: find max, min and the difference
- max = 0.5451 (green)
- min = 0.1804 (red)
- d = max − min = 0.3647
Step 4: lightness
L = (max + min) ÷ 2 = (0.5451 + 0.1804) ÷ 2 = 0.3627, so 36%.
Step 5: saturation
If max equals min, the colour is a grey and S is 0. Otherwise:
- If L is 0.5 or less: S = d ÷ (max + min)
- If L is above 0.5: S = d ÷ (2 − max − min)
Here L is 0.3627, so S = 0.3647 ÷ 0.7255 = 0.5027, so 50%.
Step 6: hue
Hue depends on which channel is the max:
| Largest channel | Hue formula (in degrees) |
|---|---|
| Red | 60 × ((G − B) ÷ d), add 360 if negative |
| Green | 60 × ((B − R) ÷ d + 2) |
| Blue | 60 × ((R − G) ÷ d + 4) |
Green is largest, so H = 60 × ((0.3412 − 0.1804) ÷ 0.3647 + 2) = 60 × (0.4409 + 2) = 146.45°, so 146°.
Result: #2E8B57 = hsl(146, 50%, 36%).
Second example: #FF5733
Result: #FF5733 = hsl(11, 100%, 60%).
Reference table
These were calculated with the same formula the colour picker uses:
| HEX | RGB | HSL |
|---|---|---|
| #FF0000 | 255, 0, 0 | hsl(0, 100%, 50%) |
| #FFFF00 | 255, 255, 0 | hsl(60, 100%, 50%) |
| #00FF00 | 0, 255, 0 | hsl(120, 100%, 50%) |
| #00FFFF | 0, 255, 255 | hsl(180, 100%, 50%) |
| #0000FF | 0, 0, 255 | hsl(240, 100%, 50%) |
| #FF00FF | 255, 0, 255 | hsl(300, 100%, 50%) |
| #808080 | 128, 128, 128 | hsl(0, 0%, 50%) |
| #FFFFFF | 255, 255, 255 | hsl(0, 0%, 100%) |
| #000000 | 0, 0, 0 | hsl(0, 0%, 0%) |
| #4F6EF7 | 79, 110, 247 | hsl(229, 91%, 64%) |
| #2E8B57 | 46, 139, 87 | hsl(146, 50%, 36%) |
| #FF5733 | 255, 87, 51 | hsl(11, 100%, 60%) |
Notice that greys, white and black all have a hue of 0. When saturation is 0, hue has no effect, so 0 is just a placeholder.
Using the Color Picker
hsl(146, 50%, 36%).The same panel shows RGB, RGBA and a CSS variable line. It also lists seven lighter tints made by mixing in white; the method is explained in how to make lighter tints of a colour.
Two limits to know: the HEX box takes six-digit codes, so expand a short code like #F53 to #FF5533 first. It does not convert HSL back to HEX; to go the other way, use the swatch to find the colour visually or use your browser's developer tools.
Common mistakes
- Forgetting to divide by 255. The formulas expect values from 0 to 1. Using 0–255 directly gives nonsense.
- Using the wrong saturation formula. The formula changes at L = 0.5. Using d ÷ (max + min) for a light colour such as #FF5733 gives 0.8 ÷ 1.2 = 67% instead of the correct 100%.
- Mixing up HSL and HSB/HSV. Design apps such as Photoshop and Figma often show HSB (also called HSV). It uses the same hue but different saturation and brightness, so the numbers won't match CSS
hsl(). For #FF5733, HSB brightness is 100% while HSL lightness is 60%. - Expecting a perfect round trip. Rounding H, S and L to whole numbers can shift the colour by one step when you convert back. If an exact match matters, keep the HEX value as the source of truth.
When HSL is the better format
- Building hover and pressed states: keep H and S, change L by a few points.
- Making a palette from one brand colour: rotate H by 30° or 180°. The Color Palette Generator does this for you.
- Theming: store H and S as CSS variables and vary L for backgrounds, borders and text.
Frequently asked questions
What is the formula to convert RGB to HSL?
Divide R, G and B by 255. Lightness is (max + min) ÷ 2. Saturation is d ÷ (max + min) if lightness is 0.5 or less, otherwise d ÷ (2 − max − min), where d = max − min. Hue is 60 × ((G − B) ÷ d) if red is largest, 60 × ((B − R) ÷ d + 2) if green is largest, or 60 × ((R − G) ÷ d + 4) if blue is largest.
What is #2E8B57 in HSL?
hsl(146, 50%, 36%). The RGB values are 46, 139 and 87; green is the largest channel, giving a hue of about 146 degrees.
Why do grey colours have a hue of 0 in HSL?
When red, green and blue are equal, saturation is 0 and the hue has no visible effect. Converters show 0 as a placeholder.
Is HSL the same as HSB or HSV?
No. They share the same hue, but saturation and brightness are calculated differently, so design-app HSB values will not match CSS hsl() values.
Put this guide into practice with our free online tool — no signup required.
Open tool