Convert a HEX code to HSL

Content last reviewed:

Type a HEX code and the HSL values appear as you go: #3B82F6 is hsl(217.2, 91.2%, 59.8%). The result has one decimal place, so typing it back in gives the same color. The switch gives you CSS notation or the 0–255 numbers from the Office Colors dialog.

HSL notation

The CSS notation matches style sheets and browser developer tools. The 0–255 notation is what the Colors dialog shows in Word, Excel and PowerPoint.

to

How do you convert HEX to HSL?

Split the code into its three RGB channels and divide each one by 255. The largest and smallest channels give you the lightness and saturation, and the channel with the highest value sets the hue on the color wheel[1].


Formula: L = (max + min) ÷ 2, S = (max − L) ÷ min(L, 1 − L), and H is an angle counted from the channel with the highest value.


Take #3B82F6. The channels are 59, 130 and 246. Divided by 255, they give 0.231, 0.510 and 0.965. The average of the largest and smallest channel is 0.598, so the lightness is 59.8%. The saturation formula gives 91.2%.


Blue is the strongest channel, so the hue calculation starts at 240 degrees. Red is weaker than green, so 22.8 degrees come off and the hue is 217.2°. The whole color written in CSS is hsl(217.2, 91.2%, 59.8%).


The HEX to RGB converter covers the first step on its own, and the RGB to HSL converter starts straight from RGB values.

What is the HSL color model?

HSL describes a color with three values. Hue is an angle on the color wheel, where 0° is red, 120° is green and 240° is blue. Saturation tells you how much color there is, so 0% gives a gray and 100% gives the full color. Lightness is 0% for black and 100% for white, and an ordinary color sits at 50%[1].


The CSS specification explains what the notation is for. RGB numbers make it hard to guess how to get a lighter version of the same color, while in HSL you change a single value[1].


George Joblove and Donald Greenberg described the model in the August 1978 issue of Computer Graphics, alongside Alvy Ray Smith’s HSV model[2]. It came to CSS with CSS Color Module Level 3, which became a W3C Recommendation on June 7, 2011[3].


If your color is in another format, such as OKLCH, Lab or Android code, the color converter shows it in every format at once.

Named CSS colors: HEX code and HSL

Some colors can be written in CSS as a word, and every one of those words has its own HEX code and HSL value[1]. The last column gives the same colors on the 0–255 scale shown in the Office Colors dialog.
CSS nameHEX codeHSL in CSSHSL in Office (0–255)
black#000000hsl(0, 0%, 0%)170, 0, 0
white#FFFFFFhsl(0, 0%, 100%)170, 0, 255
red#FF0000hsl(0, 100%, 50%)0, 255, 128
lime#00FF00hsl(120, 100%, 50%)85, 255, 128
blue#0000FFhsl(240, 100%, 50%)170, 255, 128
yellow#FFFF00hsl(60, 100%, 50%)42, 255, 128
aqua#00FFFFhsl(180, 100%, 50%)127, 255, 128
fuchsia#FF00FFhsl(300, 100%, 50%)213, 255, 128
silver#C0C0C0hsl(0, 0%, 75.3%)170, 0, 192
gray#808080hsl(0, 0%, 50.2%)170, 0, 128
maroon#800000hsl(0, 100%, 25.1%)0, 255, 64
olive#808000hsl(60, 100%, 25.1%)42, 255, 64
green#008000hsl(120, 100%, 25.1%)85, 255, 64
purple#800080hsl(300, 100%, 25.1%)213, 255, 64
teal#008080hsl(180, 100%, 25.1%)127, 255, 64
navy#000080hsl(240, 100%, 25.1%)170, 255, 64
orange#FFA500hsl(38.8, 100%, 50%)27, 255, 128
rebeccapurple#663399hsl(270, 50%, 40%)191, 128, 102
Grays have a hue of 0 in CSS and 170 in the Office dialog. At 0% saturation the hue has no effect on the color, so the CSS notation puts a zero there[1] and the Office dialog puts 170, which is two thirds of its scale.

How is HSL different from HSB and from the Office scale?

Figma shows the same color in several models, including HSL and HSB[4], and the Colors dialog in Word, Excel and PowerPoint gives HSL on a scale from 0 to 255[5]. The table puts all three side by side for eight interface colors.
HEX codeHSL in CSSHSBHSL in Office (0–255)
#3B82F6hsl(217.2, 91.2%, 59.8%)217.2°; 76%; 96.5%154, 233, 153
#EF4444hsl(0, 84.2%, 60.2%)0°; 71.5%; 93.7%0, 215, 154
#22C55Ehsl(142.1, 70.6%, 45.3%)142.1°; 82.7%; 77.3%100, 180, 116
#F59E0Bhsl(37.7, 92.1%, 50.2%)37.7°; 95.5%; 96.1%26, 235, 128
#8B5CF6hsl(258.3, 89.5%, 66.3%)258.3°; 62.6%; 96.5%183, 228, 169
#1E293Bhsl(217.2, 32.6%, 17.5%)217.2°; 49.2%; 23.1%154, 83, 45
#FAFAFAhsl(0, 0%, 98%)0°; 0%; 98%170, 0, 250
#333333hsl(0, 0%, 20%)0°; 0%; 20%170, 0, 51
The hue comes out the same in HSL and HSB, while the two models use different formulas for saturation and for the third value. In HSB the third value is 100% for every color whose strongest channel reaches 255, and in HSL a lightness of 100% means white. HSB is another name for HSV, so the RGB to HSV converter gives you HSB values to one decimal place, and on the OpenCV scale too.

How many decimal places does HSL need?

We tested this on September 13, 2026, in Chromium 151, on all 16,777,216 colors. HSL rounded to whole numbers produced a different color in 15,012,120 cases, which is 89.5% of all colors. With one decimal place every HEX code came back unchanged, and that is why the converter gives its result in this form.
HEX codeConverter resultSame values roundedColor from the rounded values
#3B82F6hsl(217.2, 91.2%, 59.8%)hsl(217, 91%, 60%)#3C83F6
#EF4444hsl(0, 84.2%, 60.2%)hsl(0, 84%, 60%)#EF4343
#22C55Ehsl(142.1, 70.6%, 45.3%)hsl(142, 71%, 45%)#21C45D
#F59E0Bhsl(37.7, 92.1%, 50.2%)hsl(38, 92%, 50%)#F59F0A
#8B5CF6hsl(258.3, 89.5%, 66.3%)hsl(258, 90%, 66%)#895AF6
#1E293Bhsl(217.2, 32.6%, 17.5%)hsl(217, 33%, 18%)#1F2A3D
In these six examples the color from the rounded values is one or two steps off per channel. The code in the style sheet then no longer matches the code in the brand guidelines. We set each color through style.color and read it back with getComputedStyle.

Which HEX code formats does this converter handle?

The field accepts and converts every one of these formats, so nothing needs cleaning up before you paste. The table shows what the converter does with each one, and it computed the results itself.
What you typeConverter resultHow we read it
#3B82F6hsl(217.2, 91.2%, 59.8%)A code with the hash, exactly as it sits in a style sheet
3b82f6hsl(217.2, 91.2%, 59.8%)The hash is optional, and lowercase letters read the same as capitals
#38Fhsl(215, 100%, 60%)We expand the three-character shorthand ourselves: #38F reads as #3388FF
#3B82F680hsla(217.2, 91.2%, 59.8%, 0.5)The last two characters are opacity — we carry them over and give the result as hsla
color: #3B82F6;hsl(217.2, 91.2%, 59.8%)Paste the whole line from a style sheet or the browser tools, we will pick the code out of it
"#3B82F6"hsl(217.2, 91.2%, 59.8%)Quotation marks from a JSON file or from JavaScript are skipped and we read the code alone
##3B82F6hsl(217.2, 91.2%, 59.8%)A double hash, the kind you get pasting next to one already typed, breaks nothing
#EF44440, 215, 154With the Notation switch set to Microsoft Office the result comes on the 0–255 scale, the one the Colors dialog in Word and Excel uses

Where will you use the HSL result?

Style sheets and browsers work with CSS notation, and Office programs work with the 0–255 scale, so set the switch to the right notation before you copy the result.

  1. CSS style sheet

    Paste the result as a property value, for example color: hsl(217.2, 91.2%, 59.8%);. CSS also takes the space-separated form with opacity after a slash, hsl(217.2 91.2% 59.8% / 50%)[1].
  2. Figma

    Select the layer and click the fill swatch in the Fill section of the right sidebar. Under the hue and opacity sliders, open the list of color models and choose HSL[4].
  3. PowerPoint, Word and Excel

    Select a shape, click Shape Fill and choose More Fill Colors[6]. On the Custom tab, set Color model to HSL and type the three Office numbers into the Hue, Sat and Lum boxes.
  4. Chrome

    Right-click the element and choose Inspect. In the styles pane, shift-click the color swatch and pick hsl(X X X / X) from the list that opens[7]. The value in the pane then switches to HSL.

Convert other units to HSL

Convert HEX to other units

Sources

  1. CSS Color Module Level 4 — HSL Colors: hsl() and hsla() functions — W3C
  2. HSL and HSV — Wikipedia
  3. CSS Color Module Level 3 — HSL color values — W3C
  4. Update fills using the color picker — Figma Help Center
  5. Choosing colors in the Colors dialog box — Microsoft Support
  6. Change the colors in a text box or shape — Microsoft Support
  7. Inspect and debug HD and non-HD colors with the Color Picker — Chrome for Developers

Every figure in the tables was computed from the unit definitions and checked arithmetically before publication. Historical values and the names of local units come from the sources listed above.

Content last reviewed: · written and checked by the Arteon team

Common questions about converting HEX to HSL

Which HSL notation should I choose in the converter?

Choose CSS for style sheets and browser developer tools. Choose Microsoft Office (0–255) when you copy the color into the Colors dialog in Word, Excel or PowerPoint, because each of the three values there runs from 0 to 255[5].

Why does a color typed into Office come back with a different HEX code?

The Colors dialog calculates HSL in whole numbers on a 0–255 scale, so some precision is lost. We checked this in Office 2016: #3B82F6 shows up as 154, 233 and 153, and those three numbers typed back in give #3C83F6. The converter uses the same algorithm, so it shows you exactly the color you will see in the program. To enter numbers read from the dialog, use the HSL to HEX converter with the Office notation.

How do I write an HSL color with transparency?

Enter an eight-character code such as #3B82F680. The converter then gives hsla(217.2, 91.2%, 59.8%, 0.5), where the fourth number is the opacity from 0 to 1[1]. The Office notation gives only the three numbers for hue, saturation and luminance.

Why do yellow and blue have the same lightness in HSL?

HSL lightness is the average of the strongest and weakest channel, so it does not match how light a color looks to the eye. The CSS specification uses exactly this example: hsl(60 100% 50%) and hsl(240 100% 50%) both have 50%, yet the yellow looks much lighter[1].

How do I make a lighter shade of a color in HSL?

Keep the hue and saturation as they are and raise only the lightness. hsl(217.2, 91.2%, 59.8%) at 70% lightness gives #6DA2F8. A ready-made lightness scale and conversion of any HSL value to a code are on the HSL to HEX converter.

Does a color in HSL have the same contrast as in HEX?

Yes, because both notations describe the same color and contrast depends on the color. Paste the result into the color contrast checker, which accepts HSL the same way it accepts a HEX code.

Arteon free tool screenshot: Convert a HEX code to HSL

Help us improve our tools

Have an idea, found a bug, or want to suggest a feature? Drop us a message.