Xerobit

RGB to HSL Converter

Enter the red, green and blue channel values of a color to convert it to HSL notation. This rgb to hsl converter runs entirely in your browser, so nothing is uploaded. It also outputs the equivalent hex code for quick reference in CSS or design tools.

Result

  • HSL
    hsl(217, 89%, 61%)
  • Hue
    217
  • Saturation
    89%
  • Lightness
    61%
  • HEX
    #4285f4

How to use the rgb to hsl converter

  1. Enter the red, green and blue channel values between 0 and 255.
  2. The tool immediately converts the rgb color to hsl notation.
  3. Copy the hsl() string directly into your CSS or design software.
  4. Use the individual hue, saturation and lightness rows if you need to adjust one component at a time.

How the RGB to HSL conversion works

The rgb to hsl algorithm normalizes each channel to a fraction between 0 and 1 by dividing by 255. It then finds the maximum and minimum of those three fractions. Lightness is simply the average of the max and min. Saturation depends on lightness: when lightness is 0 or 1 the color is pure black or white and saturation is zero; otherwise saturation equals the difference between max and min divided by a factor based on lightness. Hue is determined by which channel is the largest, using a formula that maps the result to a circle of 360 degrees.

For example, take the steel blue color with R=70, G=130, B=180. Normalized values are r=0.2745, g=0.5098, b=0.7059. The max is 0.7059 (blue) and the min is 0.2745 (red). Lightness = (0.7059 + 0.2745) / 2 = 0.4902, or about 49%. The delta is 0.4314. Since lightness is below 0.5, saturation = 0.4314 / (0.7059 + 0.2745) = 0.4402, or 44%. Because blue is the max channel, hue = 60 x (((0.2745 - 0.5098) / 0.4314) + 4) = 207.3 degrees, rounded to 207.

Common RGB colors in HSL

This table lists several standard colors with their RGB inputs and the resulting HSL output. You can use these as quick references when working with CSS.

Color nameRGBHSL
Red255, 0, 0hsl(0, 100%, 50%)
Green0, 255, 0hsl(120, 100%, 50%)
Blue0, 0, 255hsl(240, 100%, 50%)
White255, 255, 255hsl(0, 0%, 100%)
Black0, 0, 0hsl(0, 0%, 0%)
Yellow255, 255, 0hsl(60, 100%, 50%)
Cyan0, 255, 255hsl(180, 100%, 50%)
Magenta255, 0, 255hsl(300, 100%, 50%)
Gray (mid)128, 128, 128hsl(0, 0%, 50%)

Why designers use HSL over RGB

RGB describes a color as a mixture of red, green and blue light, which matches how screens emit color but does not match how people think about color. HSL separates the concept into hue (the position on the color wheel), saturation (how vivid the color is) and lightness (how dark or bright it appears). This separation makes it far easier to build palettes. If you want a lighter version of a brand color, you keep the hue and saturation fixed and raise the lightness value. In RGB you would have to guess new values for all three channels simultaneously.

CSS has supported the hsl() function for many years, and modern browsers also support space-separated syntax without commas. When you need to convert back from HSL to RGB, you can use the hsl to rgb tool. For conversions starting from a hex code, see hex to hsl.

Edge cases and rounding

Achromatic colors (grays, black and white) occur when the red, green and blue channels are all equal. In these cases the delta between max and min is zero, so hue is mathematically undefined. By convention the hue is set to 0 and saturation to 0%. The lightness correctly reflects the gray level.

Rounding is another consideration. The exact HSL values for many RGB inputs are irrational or repeating decimals. This converter rounds hue to the nearest integer degree and saturation and lightness to the nearest whole percent, matching common CSS practice. If you need more precision, the individual rows show the rounded numbers while the underlying calculation uses full floating-point accuracy before rounding. Note that converting an RGB color to HSL and back to RGB via hsl to rgb may shift the result by one unit per channel due to this rounding.

Worked examples

ExampleInputResult
Pure redRed (0-255): 255; Green (0-255): 0; Blue (0-255): 0HSL: hsl(0, 100%, 50%); Hue: 0; Saturation: 100%; Lightness: 50%; HEX: #ff0000
WhiteRed (0-255): 255; Green (0-255): 255; Blue (0-255): 255HSL: hsl(0, 0%, 100%); Hue: 0; Saturation: 0%; Lightness: 100%; HEX: #ffffff
Steel blueRed (0-255): 70; Green (0-255): 130; Blue (0-255): 180HSL: hsl(207, 44%, 49%); Hue: 207; Saturation: 44%; Lightness: 49%; HEX: #4682b4
Dark grayRed (0-255): 64; Green (0-255): 64; Blue (0-255): 64HSL: hsl(0, 0%, 25%); Hue: 0; Saturation: 0%; Lightness: 25%; HEX: #404040

FAQ

What is the HSL value of pure red?

Pure red in RGB is 255, 0, 0. Converted to HSL it becomes hsl(0, 100%, 50%). The hue is 0 degrees, saturation is fully vivid at 100% and lightness is exactly in the middle at 50%.

Why is hue 0 for both red and gray?

When a color has no saturation (all RGB channels are equal), the hue angle is mathematically undefined because there is no dominant wavelength. The convention used in CSS and most software is to default the hue to 0 in these achromatic cases.

Can I use the HSL string directly in CSS?

Yes. Modern browsers accept both the comma-separated format hsl(H, S%, L%) and the space-separated format hsl(H S% L%). You can paste the output of this rgb to hsl converter straight into your stylesheet.

Is the conversion perfectly reversible?

Because the converter rounds hue to whole degrees and saturation and lightness to whole percentages, converting back from HSL to RGB may differ by up to one unit per channel. For lossless round-tripping you would need to preserve the unrounded decimal values.

Does this tool upload my color data?

No. The entire rgb to hsl conversion happens locally in your browser using JavaScript. No network requests are made and no data leaves your device.

What range of values does RGB accept?

Each channel accepts an integer from 0 to 255 inclusive. Values outside this range will produce an error. Fractional inputs are rounded to the nearest integer before conversion.