Skip to the content

HEX to HSL Converter

Turn a HEX color code into hue, saturation and lightness, with enough decimals to get the same code back.

With or without the #. Three digits work too.

In HSL

hsl(210, 50%, 40%)

Hue
210°Alpha
100%

In the other notations

Name

steelbluenearest CSS name, #4682b4

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

HEX to HSL by hand

The converter opens with #336699. This is how that color gets from HEX to HSL, step by step.

  1. Read the three pairs of #336699 as numbers in base 16, where the first digit counts sixteen times: 33 is 3 × 16 + 3 = 51, 66 is 6 × 16 + 6 = 102 and 99 is 9 × 16 + 9 = 153. Those are the red, green and blue values.
  2. Divide each value by 255, so that it runs from 0 to 1: 51 ÷ 255 = 0.2, 102 ÷ 255 = 0.4 and 153 ÷ 255 = 0.6.
  3. The largest of the three is 0.6 and the smallest 0.2. Lightness is halfway between them: (0.6 + 0.2) ÷ 2 = 0.4, or 40%.
  4. Saturation is the gap between those two, 0.6 − 0.2 = 0.4, as a share of the most this lightness leaves room for, 1 − |2 × 0.4 − 1| = 0.8: 0.4 ÷ 0.8 = 0.5, or 50%.
  5. Blue is the largest, so the hue is 60° × ((red − green) ÷ gap + 4) = 60° × ((0.2 − 0.4) ÷ 0.4 + 4) = 210°.
  6. With one decimal at most: hsl(210, 50%, 40%).

Well-known colors in HEX and HSL

ColorHEXHSL
black#000000hsl(0, 0%, 0%)
white#ffffffhsl(0, 0%, 100%)
gray#808080hsl(0, 0%, 50.2%)
red#ff0000hsl(0, 100%, 50%)
orange#ffa500hsl(38.8, 100%, 50%)
yellow#ffff00hsl(60, 100%, 50%)
lime#00ff00hsl(120, 100%, 50%)
green#008000hsl(120, 100%, 25.1%)
cyan#00ffffhsl(180, 100%, 50%)
blue#0000ffhsl(240, 100%, 50%)
purple#800080hsl(300, 100%, 25.1%)
magenta#ff00ffhsl(300, 100%, 50%)

Why the result can have decimals

  • This example comes out in round numbers; most colors do not. #7c3aed is hsl(262.1, 83.3%, 57.8%), and rounding that to hsl(262, 83%, 58%) gives #7c3bed, a different code. One decimal is enough to get the exact HEX code back for every color.
  • A gray has no hue. When the three pairs are equal, as in #808080, the saturation is 0% and the hue is written as 0.
  • HSL lightness is not how light a color looks. #ffff00 and #0000ff both have a lightness of 50%, and the yellow is far brighter to the eye.

The color converter shows a color in all seven notations at once, with a picker to choose it by eye.

See all 8