What are HSL and HEX?
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. HEX writes the red, green and blue channels of sRGB as two hexadecimal digits each, from 00 to FF.
Useful to hand a shade you tuned in HSL back to a design tool, a brand guide or an app that only accepts six-digit HEX.
The color converter below starts from HSL and highlights HEX, next to HWB, LAB, LCH and CSS names.
HSL vs HEX
| HSL | HEX | |
|---|---|---|
| Notation | hsl(39 100% 57%) | #RRGGBB, #RGB, #RRGGBBAA |
| In CSS | all browsers | all browsers |
| Typical use | themes and shades in CSS | CSS, design handoff, brand guides |
Formula
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. Then: Write each channel (0–255) as two hexadecimal digits and join them: 255 → FF, 178 → B2 (178 = 11 × 16 + 2), 36 → 24, so rgb(255, 178, 36) is #FFB224. Values below 16 need a leading zero (10 → 0A).
What changes in the conversion
- HSL and HEX 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 HSL to HEX
- Type or paste the HSL value in its line, or pick a color with the color picker.
- Read the HEX line, which updates as you type, and check the preview swatch.
Common colors from HSL to HEX
Converted with the same code as the tool:
| Color | HSL | HEX |
|---|---|---|
| amber (stdlib.tools accent) | hsl(39, 100%, 57%) | #FFB224 |
| teal | hsl(189, 85%, 28%) | #0B7284 |
| blue | hsl(217, 91%, 60%) | #3C83F6 |
| green | hsl(142, 76%, 36%) | #16A249 |
| red | hsl(0, 72%, 51%) | #DC2828 |
| mid gray | hsl(0, 0%, 50%) | #808080 |
| black | hsl(0, 0%, 0%) | #000000 |
| white | hsl(0, 0%, 100%) | #FFFFFF |
Frequently asked questions
Is HSL to HEX 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 HEX with transparency?
Add two more digits for alpha: #FFB22480 is the amber at 50% opacity (80 hex = 128 of 255).