What are HEX and HSL?
HEX writes the red, green and blue channels of sRGB as two hexadecimal digits each, from 00 to FF. HSL describes the same sRGB color as hue (0–360°), saturation and lightness (0–100%), which makes lighter and darker shades easy to write by hand.
In HSL a hover or disabled state is one number away (change the lightness), which is why themes are often written in HSL from a HEX brand color.
The color converter below starts from HEX and highlights HSL, next to HWB, LAB, LCH and CSS names.
HEX vs HSL
| HEX | HSL | |
|---|---|---|
| Notation | #RRGGBB, #RGB, #RRGGBBAA | hsl(39 100% 57%) |
| In CSS | all browsers | all browsers |
| Typical use | CSS, design handoff, brand guides | themes and shades in CSS |
Formula
Split the six digits in pairs and read each pair as a base-16 number: FF = 15 × 16 + 15 = 255, B2 = 11 × 16 + 2 = 178, 24 = 2 × 16 + 4 = 36, so #FFB224 is rgb(255, 178, 36). A three-digit HEX doubles each digit (#F80 = #FF8800). Then: With channels scaled to 0–1: lightness L = (max + min) / 2; saturation S = (max − min) / (1 − |2L − 1|); hue H is the angle of the largest channel (red 0°, green 120°, blue 240°) shifted by the difference of the other two. The reverse builds the channels back from the same three numbers.
What changes in the conversion
- HEX and HSL describe the same sRGB color; the only difference is rounding of the last digit.
- Transparency (alpha) is kept:
#RRGGBBAA,rgb(… / 0.5),hsl(… / 50%)andoklch(… / 0.5)all carry it.
How to convert HEX to HSL
- Type or paste the HEX value in its line, or pick a color with the color picker.
- Read the HSL line, which updates as you type, and check the preview swatch.
Common colors from HEX to HSL
Converted with the same code as the tool:
| Color | HEX | HSL |
|---|---|---|
| amber (stdlib.tools accent) | #FFB224 | hsl(39, 100%, 57%) |
| teal | #0B7285 | hsl(189, 85%, 28%) |
| blue | #3B82F6 | hsl(217, 91%, 60%) |
| green | #16A34A | hsl(142, 76%, 36%) |
| red | #DC2626 | hsl(0, 72%, 51%) |
| mid gray | #808080 | hsl(0, 0%, 50%) |
| black | #000000 | hsl(0, 0%, 0%) |
| white | #FFFFFF | hsl(0, 0%, 100%) |
Frequently asked questions
Is HEX to HSL exact?
Yes, up to rounding: both describe the same 8-bit sRGB color, so converting back gives the same value.
Which format should I use in CSS?
HEX and rgb() work everywhere; hsl() is handy for shades written by hand; oklch() gives even lightness steps and wide-gamut colors in current browsers.
How do I write HSL with transparency?
Use a slash: hsl(39 100% 57% / 50%), or the older hsla(39, 100%, 57%, 0.5).