Skip to main content
7BBusyBoss

RGB to HSL Converter — Free, Instant

Convert RGB to HSL with step-by-step algorithm breakdown. Understand saturation branches, undefined hue for greys, and rounding effects.

No limitsZero data leaksSuper fast
Files never leave your browser
  • HSL
    hsl(243, 75%, 59%)
  • HEX
    #4F46E5
  • RGB
    rgb(79, 70, 229)
  • HSV
    hsv(243, 69%, 90%)
  • CMYK
    cmyk(66%, 69%, 0%, 10%)
  • OKLCH
    oklch(0.5106 0.2301 276.97)

You're on 7BusyBoss — 300+ free tools that run instantly in your browser. No signup, nothing uploaded.

Browse all Color Converters
About this tool

Grey colours return hue zero, which means nothing

When you convert a grey like rgb(128, 128, 128) to HSL, this tool returns hsl(0, 0%, 50%). The hue is mathematically undefined — the red, green and blue channels are equal, so there is no dominant colour and the formula would divide by zero. The code sidesteps this by leaving hue at 0, but that 0 reads as red everywhere else in the HSL system. If you programmatically read the hue back expecting it to mean something, you will be surprised. Always check saturation first: when S is 0, the H value carries no information at all.

Walking the conversion step by step

The algorithm starts by normalising RGB from 0–255 to 0–1 by dividing each channel by 255. Then it finds the maximum and minimum channel values. Lightness is the midpoint of these two extremes: L = (max + min) / 2. This is not perceptual — it ignores the middle channel entirely, which is the root cause of HSL's reputation for uneven-looking palettes.

Saturation uses a two-branch formula, and this is where HSL gets tricky. Below L = 0.5, saturation is S = (max − min) / (max + min). At or above L = 0.5, it switches to S = (max − min) / (2 − max − min). Why two formulas? Saturation is defined as chroma relative to the maximum chroma still possible at that lightness, and that ceiling collapses towards both ends of the scale — a colour at 95% lightness simply cannot be very far from white. The denominator has to shrink with the ceiling. Without the switch, colours near white or black would report artificially low saturation.

Hue depends on which channel is largest, and there are three cases. If green is max, H = (B − R) / d + 2. If blue is max, H = (R − G) / d + 4. If red is max, H = (G − B) / d, plus 6 when green is less than blue. That last conditional is easy to miss and it matters: with red as max and green below blue, the fraction is negative, which would put hue in the reds-through-magentas below zero. Adding 6 wraps it back around the top of the wheel instead. The result is then divided by 6 and multiplied by 360, giving a contiguous 0–360° range.

Precision: the round trip is lossier than you would expect

This tool rounds hue, saturation and lightness to whole numbers, and that rounding costs more than it sounds like. Sweeping 636,056 evenly spaced colours through RGB → HSL → RGB, 88.9% of them came back changed. Most shifted by 1 or 2 out of 255 in some channel, and the worst cases reached 5: rgb(3, 228, 234) becomes hsl(182, 97%, 46%) and returns as rgb(4, 223, 231). Plenty of colours are unaffected — rgb(123, 45, 67) converts to hsl(343, 46%, 33%) and comes back exactly — but you cannot tell in advance which yours is.

The cause is simply how few distinct values whole-number HSL has: 360 × 101 × 101 possible triples against 16.7 million RGB colours. For comparison, OKLCH reports four decimal places and drifts on well under a tenth of one percent of colours. So use HSL as a working format for reasoning about and adjusting colour, but keep the original RGB or HEX as your source of truth.

How to use the RGB to HSL Converter

Takes about a minute. No signup, no download, your data stays in your browser.

  1. 1
    Open the tool. Scroll up to the RGB to HSL Converter above — it loads instantly in your browser, no install needed.
  2. 2
    Enter your values. The fields come pre-filled with realistic defaults so you can see how it works — replace them with your own numbers.
  3. 3
    Read the result. The output updates instantly. Copy or share it — nothing is uploaded to a server, everything stays on your device.

Frequently asked questions

Common questions about the RGB to HSL Converter.

Why does my grey colour have hue zero?

Grey occurs when red, green and blue are equal, which makes the difference between max and min zero. Hue is mathematically undefined there — the formula would divide by zero. This tool returns hue 0 for all greys. That value is meaningless for grey; it is the same number as pure red, but it carries no information. Check saturation first: if it is 0, ignore the hue.

Why does the saturation formula have two cases?

Saturation measures chroma relative to the most chroma still possible at that lightness, and that ceiling collapses towards both black and white — a colour at 95% lightness cannot be far from white. So the denominator switches from max+min below lightness 0.5 to 2-max-min at or above it. Without the switch, colours near either extreme would report artificially low saturation.

Will converting RGB to HSL and back give me the exact same RGB?

Usually not. Because hue, saturation and lightness are rounded to whole numbers, 88.9% of colours in a 636,056-colour sweep came back changed. Most were off by 1 or 2 out of 255 in a channel and the worst by 5. Some round-trip exactly — rgb(123, 45, 67) does — but you cannot predict which, so keep the original RGB or HEX if exactness matters.

Why is the hue formula different when red is the largest channel?

When red is max and green is less than blue, the calculation produces a negative number, which would place the hue below zero. Adding 6 before the final scaling wraps it around the top of the colour wheel into the magentas and reds where it belongs. The green-max and blue-max cases add 2 and 4 respectively and never go negative, so they need no such correction.

What colour inputs does this tool accept?

HEX codes such as #4F46E5, plus rgb(), hsl(), hsv(), cmyk() and oklch() values, or you can use the colour picker. Anything it cannot parse shows an error message and no conversion happens.

Community rating

Discussion (0)

No comments yet. Start the discussion.