HEX to HSL Converter

HEX to HSL: #3B82F6 = hsl(217, 91%, 60%). See the formula worked step by step, a reference table, and our test of every HEX value.

How to use HEX to HSL

  1. 1Enter a HEX code such as #3B82F6.
  2. 2Read hue in degrees, saturation and lightness in percent.
  3. 3Change the lightness number to make a tint or shade, and copy the hsl() value.

Features

  • Shows hue, saturation and lightness as whole numbers
  • Tailwind blue scale converted for comparison
  • Measured rounding loss across every HEX code

How HEX to HSL conversion works

HSL rearranges the same screen colour into hue (which colour, as an angle), saturation (how far from grey) and lightness (how far from black or white). To get there from HEX you first decode the three channels, then measure the brightest and dimmest of them: their average is lightness, their spread is saturation, and which channel is brightest decides the hue sector.

  • Decode the HEX pairs to R, G, B (0–255), then divide each by 255 to get R′, G′, B′ between 0 and 1.
  • Cmax = max(R′, G′, B′), Cmin = min(R′, G′, B′), Δ = Cmax − Cmin.
  • L = (Cmax + Cmin) ÷ 2.
  • S = 0 if Δ = 0, otherwise Δ ÷ (1 − |2L − 1|).
  • H = 60° × ((G′ − B′) ÷ Δ mod 6) if R′ is largest; 60° × ((B′ − R′) ÷ Δ + 2) if G′ is largest; 60° × ((R′ − G′) ÷ Δ + 4) if B′ is largest.
  • Round to whole degrees and percentages: hsl(H, S%, L%).

Worked example: #3B82F6 to HSL

Here is the converter's own calculation for #3B82F6, step by step. The result, hsl(217, 91%, 60%), is exactly what the tool above shows for this input.

  • Split into pairs: 3B, 82, F6.
  • Red: 3B = 3 × 16 + 11 = 59.
  • Green: 82 = 8 × 16 + 2 = 130.
  • Blue: F6 = 15 × 16 + 6 = 246.
  • R′ = 59 ÷ 255 = 0.231, G′ = 0.51, B′ = 0.965.
  • Cmax = 0.965, Cmin = 0.231, Δ = 0.733.
  • L = (0.965 + 0.231) ÷ 2 = 0.598.
  • S = 0.733 ÷ (1 − |2 × 0.598 − 1|) = 0.912.
  • Blue is largest: H = 60° × ((0.231 − 0.51) ÷ 0.733 + 4) = 217.2°.
  • Rounded: hsl(217, 91%, 60%).

Tailwind CSS blue scale in HEX and HSL

Tailwind's default blue, from 50 to 950. Note that the scale doesn't hold hue fixed: it drifts a few degrees as lightness changes.

ColourHEXHSL
blue-50#EFF6FFhsl(214, 100%, 97%)
blue-100#DBEAFEhsl(214, 95%, 93%)
blue-200#BFDBFEhsl(213, 97%, 87%)
blue-300#93C5FDhsl(212, 96%, 78%)
blue-400#60A5FAhsl(213, 94%, 68%)
blue-500#3B82F6hsl(217, 91%, 60%)
blue-600#2563EBhsl(221, 83%, 53%)
blue-700#1D4ED8hsl(224, 76%, 48%)
blue-800#1E40AFhsl(226, 71%, 40%)
blue-900#1E3A8Ahsl(224, 64%, 33%)
blue-950#172554hsl(226, 57%, 21%)

Source: Tailwind CSS v3.4 default palette (tailwindcss 3.4.17)

Precision test: every HEX value through the converter

Whole-number HSL is coarser than HEX. Across all 16,777,216 HEX codes the converter produced only 2,427,032 different HSL values, and when we converted those back, just 10.583% of the original codes came back exactly. The worst drift was 5 levels on one channel (#02E4E6 returned as #02DFE3); the average was 1.2753. Invisible on screen, but it means a HEX → HSL → HEX round trip will often change the code in a design token file.

Method: every whole-number HEX value, through the converter's own code and back, compared on the 0–255 scale (how we test).

MeasureResult
HEX values tested16,777,216
Distinct HSL results2,427,032
Came back exactly10.583%
Largest change (0–255 levels)5
Average change1.2753

Last updated · Source: Pixohub exhaustive test of lib/color-math.ts

Where you'll use HEX to HSL

Building tints and shades in CSS

With hsl() you change one number to get a lighter or darker version: hsl(217 91% 60%) to hsl(217 91% 75%). Doing the same in HEX means recalculating all three pairs. The Tailwind blue scale below shows how a real design system steps lightness while drifting hue and saturation slightly.

Theming with custom properties

Many design systems store hue and saturation as CSS variables (--brand-h: 217) and compute lightness per component, so a single hue change re-themes everything. That pattern starts with converting the brand HEX to HSL.

Checking contrast by eye

Lightness gives a rough sense of how light a colour looks, though it isn't perceptual: yellow at L = 50% looks far lighter than blue at L = 50%. For accessibility checks use a contrast-ratio tool rather than HSL lightness.

Common mistakes

  • Expecting HSL saturation to match the S in a Photoshop or Figma HSB picker: they are different formulas, so the same colour has different S values (see the HEX to HSV converter).
  • Storing colours as rounded HSL and converting back to HEX for production: as the test above shows, only about one code in ten survives exactly.
  • Pasting values from Python's colorsys.rgb_to_hls(): it returns hue, lightness, saturation in that order and on a 0–1 scale.
  • Using the classic Windows colour dialog or Microsoft Office's HSL fields: they use 0–240 and 0–255 scales respectively, not degrees and percentages.

Frequently asked questions

Why does #3B82F6 become hsl(217, 91%, 60%)?

Its blue channel is brightest, which puts the hue between 180° and 300°; the spread between blue (246) and red (59) gives 91% saturation; and the average of the brightest and dimmest channels gives 60% lightness. The worked example on this page shows every step.

Can I convert HSL back to the exact same HEX code?

Often not when HSL is rounded to whole numbers. In our test of all 16.7 million HEX codes, only 10.583% came back unchanged. Keep the original HEX if you need it exactly.

Do browsers support hsl() everywhere?

Yes. hsl() has been in CSS since CSS3 and works in every current browser; the space-separated form hsl(217 91% 60% / 0.5) with alpha is from CSS Color Level 4 and is also supported by all current major browsers.

Why is the hue 0 for greys?

When red, green and blue are equal, Δ is zero, so there is no hue to measure and saturation is 0%. By convention the hue is reported as 0°.

More text, code & dev tools