RGB to HSL Converter

Enter an RGB color — rgb(99, 102, 241) or just 99, 102, 241 — to get its HSL value (hue, saturation, lightness), ready to paste into CSS.

HEX

#6366f1

RGB

rgb(99, 102, 241)

HSL

hsl(239, 84%, 67%)

HSV / HSB

hsv(239, 59%, 95%)

CMYK

cmyk(59%, 58%, 0%, 5%)

RGB 0–1

0.388, 0.400, 0.945

Text contrast (WCAG)

On white — Aa4.47:1 · AA large
On black — Aa4.70:1 · AA

What HSL means

HSL describes a color the way people talk about it. Hue is the position on the color wheel in degrees (0 = red, 120 = green, 240 = blue). Saturation is how strong the color is, from 0% (gray) to 100% (full color). Lightness runs from 0% (black) through 50% (the pure color) to 100% (white). RGB and HSL describe exactly the same colors; HSL just makes it easier to make a shade lighter, darker or less saturated without touching three numbers at once.

The RGB to HSL formula, step by step

Worked example for rgb(99, 102, 241):

  1. Divide each channel by 255: R = 0.388, G = 0.400, B = 0.945.
  2. Find the largest and smallest: max = 0.945 (blue), min = 0.388, difference d = 0.557.
  3. Lightness = (max + min) ÷ 2 = 0.667 → 67%.
  4. Saturation: if lightness is above 0.5, use d ÷ (2 − max − min), otherwise d ÷ (max + min). Here 0.557 ÷ 0.667 = 0.835 → 84%. If max equals min the color is a gray, and both hue and saturation are 0.
  5. Hue depends on which channel is largest. Red: (G − B) ÷ d. Green: (B − R) ÷ d + 2. Blue: (R − G) ÷ d + 4. Blue is largest here: (0.388 − 0.400) ÷ 0.557 + 4 = 3.979. Multiply by 60 → 238.7° → 239. A negative result gets 360 added.

Result: hsl(239, 84%, 67%). We checked this example and the ones in the table below against Python's built-in colorsys module; both give the same rounded values as this tool.

RGB to HSL in code

JavaScript:

function rgbToHsl(r, g, b) {
  r /= 255; g /= 255; b /= 255;
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
  const l = (max + min) / 2;
  let h = 0, s = 0;
  if (max !== min) {
    const d = max - min;
    s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
    if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
    else if (max === g) h = (b - r) / d + 2;
    else h = (r - g) / d + 4;
    h *= 60;
  }
  return [Math.round(h), Math.round(s * 100), Math.round(l * 100)];
}
rgbToHsl(99, 102, 241); // [239, 84, 67]

Python — note that colorsys calls it HLS and returns hue, lightness, saturation, in that order, each from 0 to 1:

import colorsys
h, l, s = colorsys.rgb_to_hls(99/255, 102/255, 241/255)
round(h * 360), round(s * 100), round(l * 100)
# (239, 84, 67)

CSS accepts both the comma syntax and the modern space-separated one:

color: hsl(239, 84%, 67%);
color: hsl(239 84% 67%);
color: hsl(239 84% 67% / 0.5); /* 50% opacity */

Common colors in RGB and HSL

ColorRGBHSLHEX
Blackrgb(0, 0, 0)hsl(0, 0%, 0%)#000000
Whitergb(255, 255, 255)hsl(0, 0%, 100%)#ffffff
Redrgb(255, 0, 0)hsl(0, 100%, 50%)#ff0000
Greenrgb(0, 128, 0)hsl(120, 100%, 25%)#008000
Limergb(0, 255, 0)hsl(120, 100%, 50%)#00ff00
Bluergb(0, 0, 255)hsl(240, 100%, 50%)#0000ff
Yellowrgb(255, 255, 0)hsl(60, 100%, 50%)#ffff00
Orangergb(255, 165, 0)hsl(39, 100%, 50%)#ffa500
Purplergb(128, 0, 128)hsl(300, 100%, 25%)#800080
Navyrgb(0, 0, 128)hsl(240, 100%, 25%)#000080
Tealrgb(0, 128, 128)hsl(180, 100%, 25%)#008080
Grayrgb(128, 128, 128)hsl(0, 0%, 50%)#808080
Silverrgb(192, 192, 192)hsl(0, 0%, 75%)#c0c0c0
Maroonrgb(128, 0, 0)hsl(0, 100%, 25%)#800000
Pinkrgb(255, 192, 203)hsl(350, 100%, 88%)#ffc0cb
Goldrgb(255, 215, 0)hsl(51, 100%, 50%)#ffd700

Frequently asked questions

What input formats work?
rgb(99, 102, 241), rgba(99, 102, 241, 0.5), the modern rgb(99 102 241) syntax, or three plain numbers. You can also paste a HEX code or an HSL value to go the other way.
Why does converting HSL back to RGB sometimes change a value by one?
HSL is rounded to whole numbers, and a rounded HSL can't always land on the original RGB exactly. For example rgb(99, 102, 241) becomes hsl(239, 84%, 67%), which converts back to rgb(100, 103, 242). The difference is invisible on screen; keep the original RGB or HEX if you need it exact.
Why is the hue 0 for gray, white and black?
When red, green and blue are equal there is no dominant color, so saturation is 0% and hue is meaningless. By convention it is written as 0.
What is the difference between HSL and HSV (HSB)?
Both use the same hue. In HSL, 100% lightness is always white; in HSV, 100% value is the brightest version of the color. CSS uses HSL; Photoshop and Figma color pickers use HSV. The converter shows both.
Does the alpha (opacity) value carry over?
No. rgba() input is accepted, but only the color channels are converted. Add the alpha back yourself, for example hsl(239 84% 67% / 0.5).

Related tools