Free tool · Developer tools
RGB to HSL converter
An RGB to HSL converter turns three channel values into a hue angle, a saturation percent and a lightness percent. The color rgb(200, 80, 120) becomes hsl(340, 52%, 55%), and the working under the result shows how each part was found.
- Free
- No sign-up
- Runs in your browser
hsl(340, 52%, 55%)Hue 340 degrees, picked by the formula ((G - B) / delta, red is largest).
- hsl(340 52% 55%)
- hsla(340, 52%, 55%, 1)
- #C85078
- Hue
- 340 deg
- Saturation
- 52.17%
- Lightness
- 54.9%
- Largest channel
- 0.7843
- Smallest channel
- 0.3137
- Delta (max - min)
- 0.4706
| Step | Formula | Value |
|---|---|---|
| Scale to 0 to 1 | R, G, B divided by 255 | 0.7843, 0.3137, 0.4706 |
| Largest and smallest | max, min | 0.7843, 0.3137 |
| Lightness | (max + min) / 2 | 0.5490 = 54.9% |
| Saturation | delta / (1 - |2L - 1|) | 0.4706 / 0.9020 = 52.17% |
| Hue | 60 x (G - B) / delta | 340 deg |
How to use the RGB to HSL Converter
- Type the Red, Green and Blue values. Each is a number from 0 to 255, and decimals such as 127.5 work too.
- Pick how many decimals you want in Decimals in the answer. Whole numbers suit most stylesheets; two decimals keep a round trip closer.
- Copy the
hsl()string from the big answer, or the space-separated andhsla()forms from the chips below it. - Open the table called The working with your numbers to see the scaled channels, the largest and smallest values, and each formula filled in.
How do you convert RGB to HSL?
The conversion takes five steps. First divide each channel by 255 so red, green and blue sit between 0 and 1. For rgb(200, 80, 120) that gives 0.7843, 0.3137 and 0.4706. Next find the largest and smallest of the three (0.7843 and 0.3137) and subtract them to get the delta, 0.4706.
Lightness is the average of the largest and smallest: (0.7843 + 0.3137) ÷ 2 = 0.5490, so 55% after rounding. Saturation is the delta divided by (1 minus the distance of 2L from 1). Here 2L is 1.0980, the distance from 1 is 0.0980, and 0.4706 ÷ 0.9020 = 0.5217, which is 52%.
Hue depends on which channel is largest. Red is largest here, so the hue is 60 × ((G minus B) ÷ delta), wrapped into the range 0 to 6 first. (0.3137 minus 0.4706) ÷ 0.4706 = negative 0.3333, which wraps to 5.6667, and 60 × 5.6667 = 340 degrees. The result is hsl(340, 52%, 55%). A green maximum adds 2 to the fraction and a blue maximum adds 4, which is why the three hue sectors start at 0, 120 and 240 degrees.
What do hue, saturation and lightness mean?
Hue is the position on the color wheel in degrees: 0 is red, 60 yellow, 120 green, 180 cyan, 240 blue and 300 magenta, and 360 comes back to red. Saturation runs from 0% (a grey) to 100% (a pure color). Lightness runs from 0% (black) through 50% (the purest version of the hue) to 100% (white).
That layout is why many people prefer HSL when they write CSS by hand. To make a button darker on hover you lower the lightness and leave the other two numbers alone. To mute a color you lower the saturation. With RGB the same edits would need all three channels to move together.
A grey has equal red, green and blue, so the delta is 0. The saturation is then 0 and the hue has no meaning, and the page shows it as 0 by convention. The same applies to black and white, which only differ in lightness.
| Color | RGB | HSL |
|---|---|---|
| Red | 255, 0, 0 | hsl(0, 100%, 50%) |
| Yellow | 255, 255, 0 | hsl(60, 100%, 50%) |
| Green | 0, 255, 0 | hsl(120, 100%, 50%) |
| Cyan | 0, 255, 255 | hsl(180, 100%, 50%) |
| Blue | 0, 0, 255 | hsl(240, 100%, 50%) |
| Magenta | 255, 0, 255 | hsl(300, 100%, 50%) |
| Mid grey | 128, 128, 128 | hsl(0, 0%, 50%) |
| White | 255, 255, 255 | hsl(0, 0%, 100%) |
| Black | 0, 0, 0 | hsl(0, 0%, 0%) |
| Your example | 200, 80, 120 | hsl(340, 52%, 55%) |
Why does the converted number not always round trip?
Rounding is the reason. The exact lightness of the example is 54.9020%, and the converter shows 55% by default. Convert hsl(340, 52%, 55%) back to RGB and red and blue return as 200 and 120, while green comes back as 81 instead of 80. Choose two decimals to keep that error smaller, and type decimal channels such as 127.5 when you are starting from a color that was itself produced by a tool.
HSL describes the same set of colors as RGB, so nothing is lost in principle. Only the number of digits you keep decides how close a round trip comes. If a design file needs an exact match, keep the original RGB or hex value next to the HSL one.
The hue shown is always below 360. A value that rounds up to 360, such as the hue of rgb(255, 0, 1) with no decimals, is written as 0 because both mean red.
Browsers accept both hsl(340, 52%, 55%) with commas and the newer space-separated form. The chips under the answer give you both, plus an hsla() form with full opacity and the hex code of the same color. For the other direction, see the hex to RGB converter, which also accepts hsl() text, or the CMYK to RGB converter.
Use it with
- CMYK to RGB Converter: CMYK to RGB converter: enter cyan, magenta, yellow and black percents to get RGB values, a hex code and a color preview. The formula is shown.
- Color Mixer: mix two or more colors and get the result codes.
- HEX Color Name Finder: nearest color name for a HEX.
Questions
What is the formula to convert RGB to HSL?
Scale the channels to 0 to 1, take the largest and smallest, then L = (max + min) ÷ 2 and S = delta ÷ (1 minus |2L minus 1|). The hue is 60 times a fraction that depends on which channel is largest. rgb(200, 80, 120) gives hsl(340, 52%, 55%).
Is HSL the same as HSV or HSB?
No. HSL and HSV share the hue but compute the other two numbers differently. In HSL, 50% lightness is the purest color and 100% is white. In HSV, 100% value is the purest color and white needs zero saturation. This page only produces HSL.
What range does each HSL value use?
Hue is 0 to 360 degrees, saturation is 0 to 100%, and lightness is 0 to 100%. Red, green and blue inputs are 0 to 255.
Why is the hue 0 for white, black and grey?
When red, green and blue are equal there is no dominant color, so the delta is 0 and the hue is undefined. The usual convention is to write 0, and the saturation is 0 as well.
Can I enter decimal RGB values?
Yes. Values such as 127.5 are accepted between 0 and 255. Anything outside that range shows a message and no result.
Which CSS forms does the page give me?
The comma form hsl(340, 52%, 55%), the space form hsl(340 52% 55%), an hsla() form with alpha 1, and the matching hex code.
The tool's results are computed in your browser by the code on this page; the explanations are checked against the tool's own output.