Xerobit

HSL to HEX Converter

This tool converts an HSL color to hex by taking hue (0 to 360), saturation (0 to 100) and lightness (0 to 100) and returning the six-digit hexadecimal code. It also provides the equivalent RGB integers and CSS rgb() string. Everything runs locally in your browser, so no color data is uploaded anywhere.

Result

  • HEX
    #4080BF
  • RGB
    64, 128, 191
  • CSS rgb()
    rgb(64, 128, 191)

How to use the hsl to hex converter

  1. Enter the hue as a degree from 0 to 360 (red is 0, green is 120, blue is 240).
  2. Set the saturation percentage from 0 (gray) to 100 (full color).
  3. Set the lightness percentage from 0 (black) to 100 (white).
  4. Read the resulting hex code, RGB integers and CSS rgb() string below.

How HSL maps to hex mathematically

The HSL model describes color using three axes: hue (an angle on the color wheel), saturation (intensity of the color) and lightness (how dark or bright it is). To convert HSL to hex, the browser first computes the RGB channels.

Given H in degrees, S and L as fractions between 0 and 1, calculate chroma C = (1 - |2L - 1|) * S. Then find an intermediate value X = C * (1 - |(H / 60) mod 2 - 1|) and a lightness offset m = L - C / 2. Depending on which 60-degree sector H falls into, assign C, X and 0 to the R, G and B channels, add m to each, multiply by 255 and round to the nearest integer. Finally, format each integer as a two-digit uppercase hexadecimal string and prepend a hash sign.

Worked example: converting HSL(210, 50%, 50%)

Take a steel-blue tone defined as hsl(210, 50%, 50%). First, normalize saturation and lightness: S = 0.5, L = 0.5. Chroma is C = (1 - |2(0.5) - 1|) * 0.5 = 0.5. The hue 210 falls in the fourth sector (180 to 240), so H' = 210 / 60 = 3.5. Compute X = 0.5 * (1 - |3.5 mod 2 - 1|) = 0.5 * (1 - |1.5 - 1|) = 0.5 * 0.5 = 0.25. The offset is m = 0.5 - 0.25 = 0.25.

In the fourth sector, the unmapped channels are (R, G, B) = (0, X, C) = (0, 0.25, 0.5). Adding m gives (0.25, 0.5, 0.75). Multiply by 255 and round: R = 64, G = 128, B = 191. In hex that is 40, 80 and BF, producing #4080BF.

Common HSL colors and their hex equivalents

This table lists frequently used colors expressed in both models. Use it as a quick reference when you need to convert HSL to hex without opening the calculator.

Color nameHSLHEX
Redhsl(0, 100%, 50%)#FF0000
Yellowhsl(60, 100%, 50%)#FFFF00
Greenhsl(120, 100%, 50%)#00FF00
Cyanhsl(180, 100%, 50%)#00FFFF
Bluehsl(240, 100%, 50%)#0000FF
Magentahsl(300, 100%, 50%)#FF00FF
Whitehsl(0, 0%, 100%)#FFFFFF
Blackhsl(0, 0%, 0%)#000000
Gray (50%)hsl(0, 0%, 50%)#808080

When to use HSL versus hex in CSS

Hex codes like #4080BF are compact and widely supported, making them ideal for design tokens, configuration files and situations where a static color is needed. However, they are not intuitive to adjust by eye. Changing brightness or shifting a palette requires converting back to another model first.

HSL is often preferred directly in stylesheets because its components map to how humans think about color. To create a hover state, you can simply lower the lightness value while keeping hue and saturation fixed. If you need to hand off a final value to a system that only accepts hex, this HSL to hex converter bridges the gap. For print workflows, you might also need to go further and use tools like hex to CMYK or CMYK to hex to match ink profiles.

Edge cases and rounding behavior

A hue of exactly 360 degrees wraps around to 0, representing the same red point on the color wheel. Saturation at 0% always produces a shade of gray regardless of the hue value, because chroma becomes zero. Lightness at 0% is always black and 100% is always white, again overriding hue and saturation.

Because the conversion involves multiplying by 255 and rounding, some HSL values do not have a perfectly reversible hex equivalent. A color converted from HSL to hex and then back via a reverse lookup may differ by one degree of hue or one percent of saturation due to the limited precision of eight bits per channel. This is normal and expected in all 24-bit sRGB color spaces.

Worked examples

ExampleInputResult
Pure redHue (0-360): 0; Saturation (0-100%): 100; Lightness (0-100%): 50HEX: #FF0000; RGB: 255, 0, 0; CSS rgb(): rgb(255, 0, 0)
CSS blueHue (0-360): 240; Saturation (0-100%): 100; Lightness (0-100%): 50HEX: #0000FF; RGB: 0, 0, 255; CSS rgb(): rgb(0, 0, 255)
Medium grayHue (0-360): 0; Saturation (0-100%): 0; Lightness (0-100%): 50HEX: #808080; RGB: 128, 128, 128; CSS rgb(): rgb(128, 128, 128)
Soft greenHue (0-360): 120; Saturation (0-100%): 40; Lightness (0-100%): 60HEX: #70C270; RGB: 112, 194, 112; CSS rgb(): rgb(112, 194, 112)

FAQ

What does HSL stand for?

HSL stands for Hue, Saturation and Lightness. Hue is an angle on the color wheel from 0 to 360, saturation is a percentage of color intensity and lightness is a percentage from black to white.

Why would I convert HSL to hex?

Hex codes are required by many design tools, image formats and older CSS properties. Converting lets you use the intuitive HSL model during design and output the exact hex string needed for implementation.

Is a hue of 360 valid?

Yes. A hue of 360 degrees is identical to 0 degrees, both representing pure red on the color wheel. The converter accepts values from 0 to 360 inclusive.

Does this tool support alpha transparency?

No. Standard HSL to hex conversion produces a six-character code without opacity. If you need an eight-character hex code with an alpha channel, convert to RGBA first and then use an RGBA to hex tool.

Can I paste an hsl() CSS string directly?

This converter expects separate numeric inputs for hue, saturation and lightness. Strip any CSS syntax such as parentheses, commas or the word 'hsl' before entering the numbers.

Are the results accurate for print design?

The output is an sRGB hex code intended for screens. Print workflows use CMYK or Pantone spot colors. After getting your hex value, use a hex to Pantone or hex to CMYK converter for print-ready values.