RGB to HSL Converter

RGB to HSL: rgb(16, 185, 129) = hsl(160, 84%, 39%). See the formula worked step by step, a reference table, and our test of every RGB value.

How to use RGB to HSL

  1. 1Enter red, green and blue from DevTools or your code.
  2. 2Read the hsl() value with whole-number degrees and percentages.
  3. 3Adjust L for hover or disabled states and paste into CSS.

Features

  • CSS-ready hsl() output
  • Tailwind emerald scale for comparison
  • Shows how much precision rounding costs

How RGB to HSL conversion works

RGB says how much red, green and blue light to mix; HSL says what colour it is and how light and vivid. The conversion looks at the brightest and dimmest channels: their midpoint is lightness, their difference (scaled for lightness) is saturation, and the order of the channels gives the hue angle.

  • R′ = R ÷ 255, G′ = G ÷ 255, B′ = B ÷ 255.
  • Cmax, Cmin and Δ = Cmax − Cmin.
  • L = (Cmax + Cmin) ÷ 2.
  • S = Δ ÷ (1 − |2L − 1|), or 0 when Δ = 0.
  • H from whichever channel is largest (red: 60° × ((G′ − B′) ÷ Δ mod 6); green: 60° × ((B′ − R′) ÷ Δ + 2); blue: 60° × ((R′ − G′) ÷ Δ + 4)).

Worked example: rgb(16, 185, 129) to HSL

Here is the converter's own calculation for rgb(16, 185, 129), step by step. The result, hsl(160, 84%, 39%), is exactly what the tool above shows for this input.

  • R′ = 16 ÷ 255 = 0.063, G′ = 0.725, B′ = 0.506.
  • Cmax = 0.725, Cmin = 0.063, Δ = 0.663.
  • L = (0.725 + 0.063) ÷ 2 = 0.394.
  • S = 0.663 ÷ (1 − |2 × 0.394 − 1|) = 0.841.
  • Green is largest: H = 60° × ((0.506 − 0.063) ÷ 0.663 + 2) = 160.1°.
  • Rounded: hsl(160, 84%, 39%).

Tailwind CSS emerald scale in RGB and HSL

Tailwind's emerald from 50 to 950, written as RGB and converted.

ColourRGBHSL
emerald-50rgb(236, 253, 245)hsl(152, 81%, 96%)
emerald-100rgb(209, 250, 229)hsl(149, 80%, 90%)
emerald-200rgb(167, 243, 208)hsl(152, 76%, 80%)
emerald-300rgb(110, 231, 183)hsl(156, 72%, 67%)
emerald-400rgb(52, 211, 153)hsl(158, 64%, 52%)
emerald-500rgb(16, 185, 129)hsl(160, 84%, 39%)
emerald-600rgb(5, 150, 105)hsl(161, 94%, 30%)
emerald-700rgb(4, 120, 87)hsl(163, 94%, 24%)
emerald-800rgb(6, 95, 70)hsl(163, 88%, 20%)
emerald-900rgb(6, 78, 59)hsl(164, 86%, 16%)
emerald-950rgb(2, 44, 34)hsl(166, 91%, 9%)

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

Precision test: every RGB value through the converter

Rounded HSL is a lossy summary of RGB: our exhaustive run over all 16,777,216 RGB colours produced 2,427,032 HSL values, and only 10.583% of colours survived the trip back. The worst case was 5 levels (#02E4E6 → #02DFE3); the average 1.2753. If you need an exact colour back, keep the RGB.

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

MeasureResult
RGB 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 RGB to HSL

Readable colour code in CSS

hsl(160 84% 39%) tells a reader "green, vivid, medium" at a glance in a way rgb(16 185 129) doesn't, and adjusting it by hand is predictable.

Hover and disabled states

A common pattern is to keep H and S and change only L for hover (a few points darker) and disabled (much lighter). The emerald scale below shows how far L moves between neighbouring steps.

Data visualisation

Charts that need categories of equal visual weight often fix S and L and space hues evenly; converting the RGB of an existing chart colour gives you the S and L to keep.

Common mistakes

  • Confusing Python's colorsys.rgb_to_hls() output order (H, L, S) with CSS's H, S, L.
  • Expecting equal L to mean equal perceived brightness: green and blue at L = 50% look very different. Use OKLCH or a contrast checker for perceptual work.
  • Mixing scales: CSS uses degrees and percentages, Office's HSL fields use 0–255, and the classic Windows colour dialog uses 0–240.
  • Rounding S and L before computing variants: work from the unrounded values or the original RGB to avoid compounding drift.

Frequently asked questions

What is rgb(16, 185, 129) in HSL?

hsl(160, 84%, 39%) — Tailwind's emerald-500. Green is the brightest channel, which puts the hue between 60° and 180°; the worked example above shows each step.

Does converting RGB to HSL lose information?

Only through rounding. With whole numbers, 10.583% of RGB colours come back exactly; the rest shift by at most 5 levels per channel.

Why do two different RGB colours give the same HSL?

Whole-number HSL has 3,672,360 combinations, and the converter only uses 2,427,032 of them for the 16.7 million RGB colours, so many neighbouring RGB colours share a rounded HSL value.

Is HSL better than RGB for CSS?

Neither is more accurate; HSL is easier to adjust by hand. For perceptually even palettes, newer CSS functions such as oklch() are better still.

More text, code & dev tools