How RGB converts to HEX and HSL
HEX simply re-encodes each RGB channel (0–255) as a 2-digit base-16 number. HSL re-describes the same color by hue (0–360°), saturation, and lightness (both in %), which are derived from the highest and lowest of the three channels.
- R,G,B — red, green, blue channels, 0–255 each
- H — hue, 0–360°
- S, L — saturation and lightness, 0–100%
More detail
Why HEX uses two digits per channel
A single base-16 digit only covers 0–15, but an RGB channel goes up to 255. Two hex digits cover 0–255 exactly (16 × 16 = 256), which is why the full form of a color code is 6 hex digits — two each for red, green, and blue. CSS also accepts a 3-digit shorthand, but only when each pair repeats the same digit (#FF0000 → #F00).
Quick check. rgb(79, 70, 229) — a common indigo/violet — converts to #4F46E5 in hex and roughly hsl(243, 75%, 59%).
Frequently asked questions
What is rgb(79, 70, 229) in hex?
#4F46E5. Each channel converts to hex separately: 79 → 4F, 70 → 46, 229 → E5.
What is rgb(79, 70, 229) in HSL?
Roughly hsl(243, 75%, 59%) — a blue-violet hue with high saturation and mid-high lightness.
What's the difference between HEX and HSL?
HEX packs the red, green, and blue channels (0–255 each) into a 6-digit base-16 code. HSL describes the same color differently — as a hue angle (0–360°) plus saturation and lightness percentages — which is often more intuitive for adjusting a color by eye.
What happens if I enter a value above 255 or below 0?
The calculator clamps it to the valid range first — anything above 255 becomes 255, anything below 0 becomes 0 — since RGB channels only exist between 0 and 255.
Why do black and white have no hue?
Black (0,0,0) and white (255,255,255) are achromatic — all three channels are equal, so there's no dominant channel to derive a hue from, and both show hue as 0 by convention.