HSL to HEX Converter (Live Color Codes & CSS Generator)

Convert hsl() and hsla() color coordinates into standard 6-digit and 8-digit hexadecimal codes. Adjust Hue, Saturation, Lightness, and Alpha with synchronized sliders, paste CSS strings directly, and generate HTML email-safe HEX codes in real time.

How Do You Convert HSL to HEX?

To convert HSL to HEX, calculate color chroma ($C = (1 - |2L - 1|) \times S$) from Saturation and Lightness fractions. Calculate intermediate values based on the Hue angle ($0^\circ\text{–}360^\circ$) to determine fractional Red, Green, and Blue channels. Multiply by 255 to yield decimal integers (0–255), and convert each channel into a 2-digit base-16 hex pair (e.g., hsl(221, 83%, 53%) becomes #2563EB).

Dynamic Lightness Ramp:

The Mathematics of HSL to HEX Conversion

Translating cylindrical HSL coordinates into base-16 hexadecimal involves computing the intermediate color chroma ($C$) and matching the Hue angle across the $360^\circ$ circle:

  1. Normalize Saturation and Lightness:
    S = Saturation / 100, L = Lightness / 100
  2. Calculate Color Chroma ($C$):
    C = (1 - Math.abs(2L - 1)) × S
  3. Calculate Intermediate Hue Value ($X$):
    X = C × (1 - Math.abs(((Hue / 60) % 2) - 1))
  4. Calculate Lightness Offset ($m$):
    m = L - (C / 2)
  5. Determine Fractional RGB Channels:
    • $0^\circ \le H < 60^\circ$: $(R', G', B') = (C, X, 0)$
    • $60^\circ \le H < 120^\circ$: $(R', G', B') = (X, C, 0)$
    • $120^\circ \le H < 180^\circ$: $(R', G', B') = (0, C, X)$
    • $180^\circ \le H < 240^\circ$: $(R', G', B') = (0, X, C)$
    • $240^\circ \le H < 300^\circ$: $(R', G', B') = (X, 0, C)$
    • $300^\circ \le H \le 360^\circ$: $(R', G', B') = (C, 0, X)$
  6. Scale to Decimal (0–255) and Format Hex:
    R = Math.round((R' + m) * 255).toString(16).padStart(2, '0')
    G = Math.round((G' + m) * 255).toString(16).padStart(2, '0')
    B = Math.round((B' + m) * 255).toString(16).padStart(2, '0')

Why Convert HSL to HEX? (HTML Email & SVG Compatibility)

While HSL is ideal for building dynamic web design systems, certain production environments strictly require hexadecimal color codes:

  • HTML Email Clients (The Microsoft Outlook Bug): Desktop versions of Microsoft Outlook use the Microsoft Word (WordML) HTML rendering engine, which completely fails to parse hsl() and rgba() CSS styles. Backgrounds and text styled in HSL render as blank white or black. Converting HSL tokens into 6-digit HEX (#RRGGBB) guarantees 100% email rendering compatibility.
  • Legacy SVG & PDF Canvas Engines: Many PDF rasterizers, vector printing libraries, and legacy SVG renderers only accept hexadecimal color strings.
  • Config Token Files: Native mobile development in Swift (iOS) and Kotlin (Android) frequently relies on base-16 hex values for primary branding constants.

Common HSL to HEX Conversion Matrix

Color Token HSL Coordinates 6-Digit HEX 8-Digit Alpha (50%) Visual Swatch
Tailwind Blue 600 hsl(221, 83%, 53%) #2563EB #2563EB80
Emerald 500 hsl(160, 84%, 39%) #10B981 #10B98180
Purple 500 hsl(258, 90%, 66%) #8B5CF6 #8B5CF680
Amber 500 hsl(38, 92%, 50%) #F59E0B #F59E0B80
Slate Dark hsl(222, 47%, 11%) #0F172A #0F172A80

Related Two-Way Color Converters:

  • HEX to HSL Converter — Reverse mapping: convert hex strings into Hue, Saturation, and Lightness coordinates.
  • HEX to RGB Converter — Convert hex codes to legacy rgb() and modern CSS Level 4 space-separated syntax.
  • RGB to HEX Converter — Translate decimal RGB integers and opacity sliders into clean 6-digit and 8-digit hex values.
  • Full Color Converter Hub — Simultaneous conversion between HEX, RGB, and HSL palettes.

Frequently Asked Questions

What is the formula for converting HSL to HEX?

To convert HSL to HEX, calculate the color chroma ($C = (1 - |2L - 1|) \times S$) from Saturation and Lightness percentages. Calculate intermediate RGB values using the Hue angle, multiply each by 255 to yield base-10 integers (0–255), and format each channel as a 2-digit hexadecimal pair.

Why do HTML email templates require HEX codes instead of HSL?

Desktop versions of Microsoft Outlook use the Microsoft Word HTML rendering engine, which does not support CSS3 HSL or RGBA color definitions. Using 6-digit HEX codes ensures consistent color rendering across all email clients.

How does HSLA convert into an 8-digit HEX code?

HSLA includes an alpha opacity channel (0% to 100%). The alpha percentage is scaled to an integer between 0 and 255 ($255 \times \text{alpha}$), converted to a 2-digit hex pair, and appended to the 6-digit hex code (#RRGGBBAA).

What happens to Hue when Saturation is 0%?

When Saturation is 0%, the color is achromatic (grayscale) and chroma is 0. The Hue angle has no mathematical effect on the resulting color; the output depends entirely on the Lightness percentage (0% = #000000, 100% = #FFFFFF).

Can I paste raw CSS HSL strings into this tool?

Yes. You can paste legacy comma-separated strings like hsl(221, 83%, 53%) or modern space-separated strings using deg, turn, rad, or slash alpha syntax into the input helper to populate the sliders and hex outputs instantly.