RGB tells a screen how much light to emit; HSL tells you what the color actually looks like. Converting the three channels into hue, saturation and lightness makes a color easy to adjust by hand.
How RGB to HSL conversion works
- Divide R, G and B by 255 so each value sits between 0 and 1.
- Take the maximum and the minimum of the three — their average is the lightness L.
- If maximum and minimum are equal, the color is grey: hue and saturation are both 0.
- Otherwise derive S from the spread between maximum and minimum, and read H from whichever channel is the maximum.
Worked example
Exact in principle. Because H, S and L are usually displayed as rounded whole numbers, converting back may shift a channel by a step or two.
RGB and HSL explained
What is RGB?
RGB describes a color as three channels of light — red, green and blue — each from 0 to 255. It mirrors how screens actually work: all three at 255 give white, all at 0 give black. RGB is the right choice whenever you need to calculate with a color, and rgba() adds transparency on top.
- Syntax:
- rgb(R, G, B)
- Range:
- 0–255 per channel
- Best for:
- code, canvas, transparency with rgba()
What is HSL?
HSL splits a color into hue (0–360° on the color wheel), saturation (how colorful, 0–100%) and lightness (how bright, 0–100%). Because each part matches the way people describe color, HSL is the easiest format for building tints, shades and consistent palettes — by hand or in code.
- Syntax:
- hsl(H, S%, L%)
- Range:
- 0–360°, 0–100%, 0–100%
- Best for:
- palettes, tints and shades, theming
RGB to HSL reference table
The most common CSS colors, converted from RGB to HSL.
| Color | RGB | HSL |
|---|---|---|
| black | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
| white | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
| red | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| lime | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| blue | rgb(0, 0, 255) | hsl(240, 100%, 50%) |
| yellow | rgb(255, 255, 0) | hsl(60, 100%, 50%) |
| orange | rgb(255, 165, 0) | hsl(39, 100%, 50%) |
| teal | rgb(0, 128, 128) | hsl(180, 100%, 25%) |
| purple | rgb(128, 0, 128) | hsl(300, 100%, 25%) |
| gray | rgb(128, 128, 128) | hsl(0, 0%, 50%) |