ImgToColor

HEX to HSL Converter

HEX to HSL converter converts 6-digit (#RRGGBB) and 3-digit (#RGB) hexadecimal color codes into Hue, Saturation, and Lightness (HSL) coordinates in real time. Perfect for creating consistent UI color ramps, harmonic color palettes, button hover states, and dynamic CSS themes.

hsl(188, 78%, 41%)
Active Color SyncHEX: #17A2B8 | RGB: rgb(23, 162, 184)
HSL CSS Stringhsl(188, 78%, 41%)
Matching HEX#17A2B8
HEX Code (#RRGGBB)Hexadecimal
HSL CoordinatesCylindrical Model
Quick Palette Presets:

Why Use Our Professional HEX to HSL Tool?

Design Token Ramping
Easily construct 50 to 900 color scales for Figma or Tailwind CSS by maintaining your brand Hue and stepping Lightness percentages systematically.
Bi-Directional Conversion
Seamlessly convert HEX to HSL or modify any HSL slider to instantly generate the matching normalized HEX code with live color synchronization.
100% Client-Side Privacy
Conversions run strictly inside your browser window without uploading color inputs, project palettes, or telemetry data to third-party endpoints.

How to Convert HEX to HSL in 3 Simple Steps

Follow this quick guide to translate base-16 hex values into intuitive cylindrical HSL coordinates.

1
Enter Any Hexadecimal Color Code

Type or paste any 6-digit (such as #17A2B8) or shorthand 3-digit (such as #39B) HEX code into the dedicated input field. The parser automatically strips leading hash symbols and sanitizes characters.

2
Instant Two-Stage Mathematical Decoding

Our engine decodes base-16 channels into decimal RGB values, then projects those cartesian coordinates onto the 360-degree cylindrical HSL color wheel in real time.

3
Copy Formatted HSL Output

Click the Copy button to immediately grab the formatted hsl(H, S%, L%) code for direct use in your CSS stylesheets, Tailwind configuration, Sass mixins, or design token repositories.

Understanding the Two-Stage HEX to HSL Conversion

Explore the two-step mathematical transformation from alphanumeric base-16 strings to cylindrical color coordinates.

Stage 1: Base-16 Decoding to Decimal

First, the 6-digit HEX code (#RRGGBB) is split into two-character pairs and converted to decimal RGB values (0-255):

R = parseInt(hex.substr(1, 2), 16)
G = parseInt(hex.substr(3, 2), 16)
B = parseInt(hex.substr(5, 2), 16)

Each channel is then normalized between 0.0 and 1.0 by dividing by 255:r = R / 255, g = G / 255, b = B / 255

Stage 2: Cylindrical Coordinate Projection

From the normalized r, g, and b values, we determine max, min, and delta (max - min):

  • Lightness: L = (max + min) / 2
  • Saturation: S = delta / (1 - |2L - 1|)
  • Hue: Calculated based on whether Red, Green, or Blue is maximum
Yields: hsl(Hue 0-360, Saturation 0-100%, Lightness 0-100%)

Architecting Design Systems and Color Scales with HSL

Why modern product teams at companies like Stripe, Vercel, and GitHub build design tokens around HSL color models.

Harmonic Palettes

By locking the Saturation and Lightness while incrementing the Hue angle by fixed degrees, you generate complementary (180°), triadic (120°), or split-complementary schemes with guaranteed visual harmony.

WCAG Accessibility

HSL simplifies contrast ratio calculations. You can guarantee WCAG AA compliance (4.5:1 ratio) by ensuring text elements have a minimum 40% to 50% Lightness separation from their background color.

Dark Mode Inversion

Implementing dark mode becomes as straightforward as swapping Lightness values: a card background with 95% Lightness in light mode flips to 12% Lightness in dark mode while retaining brand hue.

HEX to HSL Code Snippets for Developers

Use these modular functions in TypeScript, JavaScript, Python, and Sass design systems.

JavaScript / TypeScript Implementation
function hexToHsl(hex: string): { h: number; s: number; l: number } {
  let c = hex.replace('#', '');
  if (c.length === 3) c = c.split('').map(x => x + x).join('');
  const num = parseInt(c, 16);
  let r = ((num >> 16) & 255) / 255;
  let g = ((num >> 8) & 255) / 255;
  let b = (num & 255) / 255;

  const max = Math.max(r, g, b), min = Math.min(r, g, b);
  let h = 0, s = 0, l = (max + min) / 2;

  if (max !== min) {
    const d = max - min;
    s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
    switch (max) {
      case r: h = (g - b) / d + (g < b ? 6 : 0); break;
      case g: h = (b - r) / d + 2; break;
      case b: h = (r - g) / d + 4; break;
    }
    h /= 6;
  }
  return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
}
Python 3 (colorsys module)
import colorsys

def hex_to_hsl(hex_code: str) -> str:
    h = hex_code.lstrip('#')
    if len(h) == 3:
        h = ''.join(c * 2 for c in h)
    r, g, b = (int(h[i:i+2], 16) / 255.0 for i in (0, 2, 4))
    hue, light, sat = colorsys.rgb_to_hls(r, g, b)
    return f"hsl({round(hue * 360)}, {round(sat * 100)}%, {round(light * 100)}%)"

# Example:
print(hex_to_hsl("#17A2B8")) # "hsl(188, 78%, 41%)"
SCSS Dynamic Tone Generator
$brand-hex: #17A2B8;

// Native Sass color manipulation
.card-theme {
  background-color: $brand-hex;
  border-color: darken($brand-hex, 15%);
  &:hover {
    background-color: lighten($brand-hex, 10%);
  }
}
CSS Custom Properties
:root {
  /* Store HSL components separately */
  --accent-h: 188;
  --accent-s: 78%;
  --accent-l: 41%;
}

.badge {
  background: hsl(var(--accent-h) var(--accent-s) var(--accent-l));
  color: hsl(var(--accent-h) var(--accent-s) 95%);
}

HEX to HSL Color Reference Chart

Quick lookup reference showing popular web design colors with their exact HEX codes, HSL coordinates, and RGB equivalents.

PreviewColor NameHEX CodeHSL ValueRGB ValueDesign Application
Pure Red#FF0000hsl(0, 100%, 50%)rgb(255, 0, 0)Error alerts, urgent callouts
Pure Green#00FF00hsl(120, 100%, 50%)rgb(0, 255, 0)Success states, system online
Pure Blue#0000FFhsl(240, 100%, 50%)rgb(0, 0, 255)Primary actions, hyperlinks
Pure Yellow#FFFF00hsl(60, 100%, 50%)rgb(255, 255, 0)Warning banners, highlights
Pure Cyan#00FFFFhsl(180, 100%, 50%)rgb(0, 255, 255)Accent tags, vibrant graphics
Pure Magenta#FF00FFhsl(300, 100%, 50%)rgb(255, 0, 255)Creative badges, gradients
Teal Lagoon#17A2B8hsl(188, 78%, 41%)rgb(23, 162, 184)Modern SaaS brand primary
Royal Indigo#4B0082hsl(275, 100%, 25%)rgb(75, 0, 130)Deep navigation headers
Vivid Tangerine#FF8243hsl(20, 100%, 63%)rgb(255, 130, 67)Secondary buttons, badges
Amethyst Violet#9966CChsl(270, 50%, 60%)rgb(153, 102, 204)Feature highlights, cards
Forest Evergreen#228B22hsl(120, 61%, 34%)rgb(34, 139, 34)Nature themes, confirmed badges
Slate Steel#4682B4hsl(207, 44%, 49%)rgb(70, 130, 180)Secondary text, border accents

Frequently Asked Questions About HEX to HSL

Learn how to master color transformations, CSS custom property tokens, and programmatic palette scaling.

Explore Related Color Conversion Tools

Switch easily between digital color models with our full collection of online tools.