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.
Why Use Our Professional HEX to HSL Tool?
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.
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.
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.
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.
First, the 6-digit HEX code (#RRGGBB) is split into two-character pairs and converted to decimal RGB values (0-255):
Each channel is then normalized between 0.0 and 1.0 by dividing by 255:r = R / 255, g = G / 255, b = B / 255
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
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.
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.
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.
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.
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) };
}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%)"$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%);
}
}: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.
| Preview | Color Name | HEX Code | HSL Value | RGB Value | Design Application |
|---|---|---|---|---|---|
| Pure Red | #FF0000 | hsl(0, 100%, 50%) | rgb(255, 0, 0) | Error alerts, urgent callouts | |
| Pure Green | #00FF00 | hsl(120, 100%, 50%) | rgb(0, 255, 0) | Success states, system online | |
| Pure Blue | #0000FF | hsl(240, 100%, 50%) | rgb(0, 0, 255) | Primary actions, hyperlinks | |
| Pure Yellow | #FFFF00 | hsl(60, 100%, 50%) | rgb(255, 255, 0) | Warning banners, highlights | |
| Pure Cyan | #00FFFF | hsl(180, 100%, 50%) | rgb(0, 255, 255) | Accent tags, vibrant graphics | |
| Pure Magenta | #FF00FF | hsl(300, 100%, 50%) | rgb(255, 0, 255) | Creative badges, gradients | |
| Teal Lagoon | #17A2B8 | hsl(188, 78%, 41%) | rgb(23, 162, 184) | Modern SaaS brand primary | |
| Royal Indigo | #4B0082 | hsl(275, 100%, 25%) | rgb(75, 0, 130) | Deep navigation headers | |
| Vivid Tangerine | #FF8243 | hsl(20, 100%, 63%) | rgb(255, 130, 67) | Secondary buttons, badges | |
| Amethyst Violet | #9966CC | hsl(270, 50%, 60%) | rgb(153, 102, 204) | Feature highlights, cards | |
| Forest Evergreen | #228B22 | hsl(120, 61%, 34%) | rgb(34, 139, 34) | Nature themes, confirmed badges | |
| Slate Steel | #4682B4 | hsl(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.