Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

HSL to hex converter

An HSL to hex converter turns a hue, a saturation and a lightness into a six digit color code. The values hsl(210, 50%, 40%) give #336699, which is rgb(51, 102, 153).

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Hue is an angle on the color wheel, saturation and lightness are percents. Opacity only changes the eight digit hex line.

Hex color

#336699from hsl(210, 50%, 40%)

  • rgb(51, 102, 153)
  • Red 51
  • Green 102
  • Blue 153
Hex code
#336699
Short hex
#369
Hex with opacity
#336699FF
CSS RGB value
rgb(51, 102, 153)
Hue on the wheel
210 degrees
Shades of hue 210 at 50% saturation
LightnessHex
10%#0D1A26
30%#264D73
50%#4080BF
70%#8CB3D9
90%#D9E6F2

How to use the HSL to HEX Converter

  1. Type the Hue as an angle from 0 to 360. Larger or negative numbers wrap around the wheel.
  2. Set Saturation and Lightness as percents from 0 to 100.
  3. Copy the hex code with the button, or read the short form and the RGB value in the list.
  4. Use Opacity if you need the eight digit form that carries transparency.

How do you convert HSL to hex?

HSL describes a color with three numbers: hue is the position on the color wheel in degrees, saturation is how vivid the color is, and lightness runs from black at 0% to white at 100%. Hex is the same color written as three channel values in base 16, one pair of digits each for red, green and blue.

The conversion has two steps. First the three HSL numbers become red, green and blue between 0 and 255. Then each channel is written in base 16. Take hsl(210, 50%, 40%). The chroma is (1 minus the absolute value of 2 times 0.4 minus 1) times 0.5, which is 0.4. The hue 210 divided by 60 is 3.5, so the color sits in the cyan to blue sector. The middle value is 0.4 times (1 minus the absolute value of 1.5 minus 1), which is 0.2, and the lightness offset is 0.4 minus 0.2, which is 0.2. That gives red 0.2, green 0.4 and blue 0.6, or 51, 102 and 153 after multiplying by 255. In base 16 those are 33, 66 and 99, so the code is #336699.

The page rounds each channel to the nearest whole number, with halves rounded up, before it writes the digits.

Common colors converted with the same formula
ColorHSLRGBHex
Redhsl(0, 100%, 50%)rgb(255, 0, 0)#FF0000
Yellowhsl(60, 100%, 50%)rgb(255, 255, 0)#FFFF00
Greenhsl(120, 100%, 25%)rgb(0, 128, 0)#008000
Cyanhsl(180, 100%, 50%)rgb(0, 255, 255)#00FFFF
Bluehsl(240, 100%, 50%)rgb(0, 0, 255)#0000FF
Magentahsl(300, 100%, 50%)rgb(255, 0, 255)#FF00FF
Mid grayhsl(0, 0%, 50%)rgb(128, 128, 128)#808080
Steel bluehsl(210, 50%, 40%)rgb(51, 102, 153)#336699

What do hue, saturation and lightness mean?

Hue is an angle. Red is at 0, yellow at 60, green at 120, cyan at 180, blue at 240 and magenta at 300. The wheel is a loop, so 360 is the same color as 0, and a negative angle counts backward: -120 lands on 240, which is pure blue. Type any number and the page wraps it for you.

Saturation of 0% removes all color and leaves a gray, whatever the hue. At hue 77, saturation 0% and lightness 40% the result is #666666, with all three channels equal to 102. Lightness of 50% shows the color at full strength, while values toward 0% darken it and values toward 100% wash it out. At 0% or 100% lightness the hue no longer matters, because the result is black or white.

Because lightness moves in a straight line, it is an easy way to build shades of one color. The table below the result keeps your hue and saturation and steps the lightness. For the default color it reads 10% #0D1A26, 30% #264D73, 50% #4080BF, 70% #8CB3D9, 90% #D9E6F2.

How do short hex and opacity work?

A hex code can be shortened to three digits when each pair repeats one digit. Pure red, hsl(0, 100%, 50%), is #FF0000 and can be written as #F00. The default color #336699 shortens to #369. A color such as hsl(30, 80%, 60%) is #EB9947 and has no short form, so the page says so.

Opacity adds a fourth pair of digits at the end. The value is the percent of opacity scaled to 255 and written in base 16, so 100% is FF, 50% is 80 and 0% is 00. The default color at 50% opacity becomes #33669980. Editors and style sheets that read eight digit hex understand this form; older tools may not, and then the six digit code plus a separate opacity setting is the safer choice.

The hue range is stated in the CSS Color specification, which normalizes the hue angle to 0 up to 360 degrees.

Why does my converted color differ slightly from a design tool?

HSL values are often shown rounded to whole numbers. A color picked as hsl(210, 50%, 40%) is exact, but a color that was first stored as hex and later displayed in HSL has been rounded once already, so converting back can move a channel by 1. Typing decimals such as 210.4 for the hue keeps more detail, and the page accepts them.

The result is a color in the standard screen color space as the formula describes it. This page does not apply a display profile, so a monitor with a different calibration can show the same code a little differently.

Use it with

Questions

How do I convert HSL to hex by hand?

Find the chroma as (1 minus |2L minus 1|) times S, find the middle value from the hue sector, add the lightness offset, scale each channel to 255 and write it in base 16. For hsl(210, 50%, 40%) that gives #336699.

What is hsl(0, 100%, 50%) in hex?

It is #FF0000, pure red, which can also be written as #F00.

Can the hue be above 360 or below 0?

Yes. The hue is an angle on a loop, so 360 equals 0, 480 equals 120 and -120 equals 240. The page wraps the number before it converts.

Why is the result gray when saturation is 0%?

With no saturation the three channels are equal, so the color has no hue. At lightness 40% each channel is 102, which is #666666.

What does the opacity field change?

Only the eight digit line. It appends the opacity as two hex digits, so 50% opacity on #336699 gives #33669980. The six digit code does not change.

Is anything I type sent to a server?

No. The conversion is arithmetic done by the page itself, so the numbers stay on this device.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.