FormatterHQ

HSL to RGB Converter

Convert hue, saturation and lightness into red, green and blue channels from 0 to 255, updated live as you type.

Loading tool…
Ready.

How to use the HSL to RGB Converter

  1. Type or paste an HSL color into the HSL field, such as hsl(9, 100%, 64%) or 9 100 64.
  2. The RGB field shows the matching rgb(r, g, b) value with whole-number channels as you type.
  3. If the value cannot be read, the field is marked and the status line explains why, so you can fix it.
  4. Copy the rgb() value with the button next to the field into your code, canvas drawing or graphics API call.

HSL to RGB conversion with the math shown

Use this HSL to RGB converter when you have a color as hue, saturation and lightness but the place you need it only speaks red, green and blue. Canvas pixel data, most graphics libraries, LED controllers and many image APIs work with three 0–255 channels, not with degrees and percentages.

The two models describe the same sRGB colors. HSL is just a friendlier coordinate system laid over the RGB cube, which is why the conversion is exact apart from rounding to whole numbers at the end.

The formula used

The tool uses a compact form of the standard HSL-to-RGB algorithm. With S and L as fractions (64% = 0.64) and H in degrees:

a    = S × min(L, 1 − L)
k(n) = (n + H / 30) mod 12
f(n) = L − a × max(−1, min(k − 3, 9 − k, 1))

R = 255 × f(0)    G = 255 × f(8)    B = 255 × f(4)

It produces the same numbers as the textbook chroma-and-sector method, without a six-way branch on the hue.

Worked example: hsl(9, 100%, 64%)

Here a = 1 × min(0.64, 0.36) = 0.36 and H / 30 = 0.3.

R: k = 0.3  → min(−2.7, 8.7, 1) = −2.7 → max(−1, −2.7) = −1
   f = 0.64 + 0.36       = 1.00  → 255
G: k = 8.3  → min(5.3, 0.7, 1)   = 0.7
   f = 0.64 − 0.36 × 0.7 = 0.388 → 98.9 → 99
B: k = 4.3  → min(1.3, 4.7, 1)   = 1
   f = 0.64 − 0.36       = 0.28  → 71.4 → 71

hsl(9, 100%, 64%)  →  rgb(255, 99, 71)

The result is tomato, one of the CSS named colors.

What the parser accepts

  • Legacy and modern CSS syntax: hsl(210, 100%, 50%) and hsl(210 100% 50%) both give rgb(0, 128, 255).
  • Fractions for saturation and lightness: hsl(207, 0.44, 0.49) is read as 44% and 49%, giving rgb(70, 130, 180).
  • Hue is read in degrees unless it carries a CSS angle unit: 0.5turn, 200grad and 3.1416rad are all converted to 180°.
  • An alpha value is accepted but dropped from rgb() output. Use HSL to RGBA to keep it.

Common mistakes

Mixing up HSL and HSV is the classic one. Both start with hue and saturation, but the third number means something different, so hsl(0, 100%, 100%) is white while an HSV value of 0, 100%, 100% is pure red. If your numbers came from a color picker labelled HSB, convert them with the HSV tools instead.

Another is expecting a perfect round trip. Converting rgb(46, 139, 87) to HSL and rounding to whole percents gives hsl(146, 50%, 36%), which converts back to rgb(46, 138, 86). Keep decimals if you plan to go back and forth. The reverse direction lives at RGB to HSL, and HEX to RGB helps when your source is a hex code.

Convert HSL to RGB in Python

The standard library's colorsys module does the HSL to RGB math, with two traps. The function is named hls_to_rgb() and takes its arguments in that order: hue, lightness, saturation. Passing them in CSS order swaps two values without raising an error. It also works on a 0–1 scale throughout, so divide the hue by 360 and the percentages by 100 on the way in, then multiply each channel by 255 and round on the way out.

import colorsys

def hsl_to_rgb(h, s, l):
    """h in degrees, s and l in percent; returns 0-255 integers."""
    r, g, b = colorsys.hls_to_rgb(h / 360, l / 100, s / 100)
    return round(r * 255), round(g * 255), round(b * 255)

print(hsl_to_rgb(9, 100, 64))    # (255, 99, 71)
print(hsl_to_rgb(207, 44, 49))   # (70, 130, 180)
print(hsl_to_rgb(146, 50, 36))   # (46, 138, 86)

The first color in the snippet is the one the converter above starts with; type the other two into it to compare each result with the script.

Frequently asked questions

What is the formula to convert HSL to RGB?
Compute chroma C = (1 − |2L − 1|) × S, X = C × (1 − |(H/60) mod 2 − 1|) and m = L − C/2. Place C and X in the channel order dictated by the hue sector, add m to each and multiply by 255. The compact k(n) form used by this tool gives identical results.
Why are my RGB values whole numbers?
Standard 8-bit RGB has 256 levels per channel, so each channel is rounded to the nearest integer between 0 and 255. That rounding is the only information lost in the conversion.
Does HSL to RGB change the color?
No. HSL is a different way of addressing the same sRGB color space, so the color stays the same. Only the notation changes, plus rounding to whole channel values.
Can I paste HSL values without the percent signs?
Yes. An entry such as 9, 100, 64 or 9 100 64 is read as degrees, saturation percent and lightness percent. Values between 0 and 1 with decimals are treated as fractions of 100%.
What happens with a hue above 360 or below 0?
Hue is an angle, so it wraps around the color wheel. 400° is treated as 40° and −90° as 270°, exactly as browsers do.

Last updated October 3, 2026

Related tools

RGB to HSL Converter Convert RGB colour values to HSL instantly, with a live colour swatch preview, colour picker and copy buttons. CMYK to HSL Converter Convert CMYK colour values to HSL instantly, with a live colour swatch preview, colour picker and copy buttons. HEX to HSL Converter Convert HEX colour values to HSL instantly, with a live colour swatch preview, colour picker and copy buttons. HSL to CMYK Converter Convert HSL colour values to CMYK instantly, with a live colour swatch preview, colour picker and copy buttons. HSL to HEX Converter Convert HSL colour values to HEX instantly, with a live colour swatch preview, colour picker and copy buttons. HSL to HSV Converter Convert HSL colour values to HSV instantly, with a live colour swatch preview, colour picker and copy buttons. HSL to RGBA Converter Convert HSL colour values to RGBA instantly, with a live colour swatch preview, colour picker and copy buttons. HSV to CMYK Converter Convert HSV colour values to CMYK instantly, with a live colour swatch preview, colour picker and copy buttons. HSV to Colortone Converter Generate the tints, shades and tones of a HSV colour as a palette with swatches and ready-to-copy codes. HSV to HEX Converter Convert HSV colour values to HEX instantly, with a live colour swatch preview, colour picker and copy buttons. HSV to HSL Converter Convert HSV colour values to HSL instantly, with a live colour swatch preview, colour picker and copy buttons. HSV to RGB Converter Convert HSV colour values to RGB instantly, with a live colour swatch preview, colour picker and copy buttons.