HEX to HSL Converter

Enter a hex code to get its hue, saturation and lightness as a ready-to-use CSS hsl() value.

How to convert HEX to HSL with this tool

  1. Enter a hex code such as #6366F1.
  2. Read the HSL card: hue 239°, saturation 84%, lightness 67%.
  3. Press Copy to get hsl(239, 84%, 67%), ready to paste into CSS.
  4. To test a variant, edit the lightness in that hsl() string, paste it back into the input and read its new HEX.

The HEX to HSL formula

Start by converting the hex pairs to RGB and dividing each channel by 255. #6366F1 is rgb(99, 102, 241), which gives R = 0.388, G = 0.400 and B = 0.945.

  • Lightness is the average of the highest and lowest channel: (0.945 + 0.388) ÷ 2 = 0.667, or 67%.
  • Saturation is the difference between them, 0.557, divided by 1 − |2L − 1|, which is 0.667. That gives 0.835, or 84%.
  • Hue depends on which channel is highest. Here it is blue, so H = 60 × ((R − G) ÷ 0.557 + 4) = 60 × 3.979 ≈ 239°.

Rounding to whole numbers is standard, but it costs precision. Convert hsl(239, 84%, 67%) back and you get #6467F2, one step off in every channel, so keep the original hex as your source of truth.

When HSL is handy for theming

HSL gives hue its own number, which makes quick theme work in CSS easy to read. Store the hue once and derive states from it:

  • --brand-h: 239;
  • Base: hsl(var(--brand-h) 84% 67%)
  • Hover: hsl(var(--brand-h) 84% 57%)
  • Subtle background: hsl(var(--brand-h) 84% 95%)

Changing --brand-h re-colors the whole set, which helps with multi-brand themes or a user-selected accent. For a fuller ladder of lighter and darker steps, the shades, tints and tones generator produces 10% increments from one color.

Where HSL falls short

HSL is a cylindrical re-mapping of sRGB, not a model of vision, so the same L does not mean the same perceived lightness. hsl(60 100% 50%) (yellow) and hsl(240 100% 50%) (blue) both have L = 50%, yet yellow on white measures 1.07:1 and blue on white 8.59:1. OKLCH puts the same two colors at 96.8% and 45.2% lightness.

In practice, an HSL scale that looks even for one hue looks uneven for another, you cannot predict text contrast from L, and blues drift toward purple as you lighten them. For scales that need to look consistent across hues, convert to OKLCH instead, and verify text pairs in the contrast checker.

Frequently asked questions

How do I convert HEX to HSL?

Convert the hex code to RGB and scale each channel to 0–1. Lightness is the average of the highest and lowest channel, saturation comes from their difference, and hue from which channel is highest. #6366F1 works out to hsl(239, 84%, 67%).

What do the HSL values mean?

Hue is an angle from 0 to 360 degrees, where 0 is red, 120 is green and 240 is blue. Saturation runs from 0% gray to 100% full color, and lightness from 0% black through 50% pure hue to 100% white.

Why doesn't HSL convert back to my exact hex color?

Whole-number HSL values are rounded, so a round trip can shift channels slightly. hsl(239, 84%, 67%) converts back to #6467F2 rather than the original #6366F1.

Is HSL the same as HSB?

No. In HSL, 100% lightness is always white, while in HSB (also called HSV) 100% brightness gives the pure hue. The converter shows both cards, so you can compare them for the same color.

Should I use HSL or OKLCH for a design system?

OKLCH is the safer choice for scales and tokens, because equal lightness steps look equally light across hues. HSL is fine for quick adjustments to a single color.

Related tools