The ultimate online tool to convert HEX color codes (#RRGGBB) to HSL (Hue, Saturation, Lightness) format. Ideal for web developers working with CSS, JavaScript, TypeScript, Tailwind CSS, and designers using Photoshop or other design applications.
Transform hexadecimal colors to HSL with precision for more intuitive color manipulation, responsive design, and dynamic color schemes. Perfect for frontend development, UX/UI design, and creating accessible web interfaces.
Easily integrate this professional HEX to HSL converter tool into your own website, blog, or web application. Simply copy the iframe code below and paste it into your HTML:
<iframe
src="https://rgbatohex.com/tools/hex-to-hsl-converter?embed=true"
width="100%"
height="500"
style="border:none;border-radius:12px;overflow:hidden;"
title="HEX to HSL Color Converter"
></iframe>
Customize the initial HEX color value of the embedded tool using URL parameters for a seamless integration:
For example, to set red (#FF0000) as the initial color:
<iframe
src="https://rgbatohex.com/tools/hex-to-hsl-converter?embed=true&defaultColor=FF0000"
width="100%"
height="500"
style="border:none;border-radius:12px;overflow:hidden;"
title="HEX to HSL Color Converter - Red"
></iframe>
Modern web design often requires fine control over colors, especially hue and lightness adjustments. Converting your HEX colors to HSL allows more intuitive adjustments:
Try converting your brand colors to HSL, then adjust the hue, saturation, and lightness values to create harmonious color schemes.
#FF0000 → hsl(0, 100%, 50%)
#00FF00 → hsl(120, 100%, 50%)
#0000FF → hsl(240, 100%, 50%)
#808080 → hsl(0, 0%, 50%)
#800080 → hsl(300, 100%, 25%)
#FFFF00 → hsl(60, 100%, 50%)
HSL (Hue, Saturation, Lightness) is a cylindrical color model designed to align more intuitively with human perception of color. It represents a more accessible alternative to hexadecimal notation and RGB color models:
This JavaScript function converts HEX colors to HSL format:
function hexToHsl(hex) {
// Remove # if present
hex = hex.replace(/^#/, '');
// Parse the hex values
let r = parseInt(hex.substring(0, 2), 16) / 255;
let g = parseInt(hex.substring(2, 4), 16) / 255;
let b = parseInt(hex.substring(4, 6), 16) / 255;
// Find min and max values to determine lightness
let max = Math.max(r, g, b);
let min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
// Achromatic (gray)
h = s = 0;
} else {
let 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;
}
// Convert to standard HSL ranges
h = Math.round(h * 360);
s = Math.round(s * 100);
l = Math.round(l * 100);
return `hsl(${h}, ${s}%, ${l}%)`;
}
// Example usage
const hslColor = hexToHsl('#3E82FC'); // Returns "hsl(217, 97%, 62%)"
This function handles the mathematical conversion from the hexadecimal representation to the HSL color space, following the standard color conversion algorithm.
Modern CSS supports HSL directly, allowing for more intuitive color manipulation:
:root {
/* Define base colors using HSL */
--primary-hue: 217;
--primary-saturation: 97%;
--primary-lightness: 62%;
/* Create the primary color and variations */
--primary-color: hsl(var(--primary-hue), var(--primary-saturation), var(--primary-lightness));
--primary-dark: hsl(var(--primary-hue), var(--primary-saturation), calc(var(--primary-lightness) - 20%));
--primary-light: hsl(var(--primary-hue), var(--primary-saturation), calc(var(--primary-lightness) + 15%));
/* Create a complementary color (opposite on the color wheel) */
--complementary-color: hsl(calc(var(--primary-hue) + 180), var(--primary-saturation), var(--primary-lightness));
}
/* Using the HSL variables */
.button-primary {
background-color: var(--primary-color); /* hsl(217, 97%, 62%) equivalent to #3E82FC */
color: white;
}
.button-primary:hover {
background-color: var(--primary-dark);
transition: background-color 0.3s ease;
}
Using HSL in CSS variables provides powerful flexibility for creating dynamic themes and consistent color schemes.
A type-safe implementation for TypeScript applications:
interface HSLColor {
h: number; // 0-360
s: number; // 0-100
l: number; // 0-100
}
function hexToHsl(hex: string): HSLColor {
// Remove # if present
hex = hex.replace(/^#/, '');
// Parse the hex values
const r = parseInt(hex.substring(0, 2), 16) / 255;
const g = parseInt(hex.substring(2, 4), 16) / 255;
const b = parseInt(hex.substring(4, 6), 16) / 255;
// Find min and max values
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h = 0;
let s = 0;
const 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;
}
// Convert to standard HSL ranges
return {
h: Math.round(h * 360),
s: Math.round(s * 100),
l: Math.round(l * 100)
};
}
// Example usage
const blueHsl: HSLColor = hexToHsl('#3E82FC');
console.log(`HSL: ${blueHsl.h}, ${blueHsl.s}%, ${blueHsl.l}%`);
TypeScript's type safety ensures reliable color manipulations in larger applications, preventing common errors.
Customize Tailwind CSS using HSL values in your configuration:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
primary: {
// Equivalent to #3E82FC in HEX
DEFAULT: 'hsl(217, 97%, 62%)',
light: 'hsl(217, 97%, 77%)',
dark: 'hsl(217, 97%, 47%)',
},
secondary: {
DEFAULT: 'hsl(37, 97%, 62%)', // Complementary color
light: 'hsl(37, 97%, 77%)',
dark: 'hsl(37, 97%, 47%)',
},
},
// Use HSL for opacity-enabled colors
backgroundColor: ({ theme }) => ({
...theme('colors'),
'primary-50': 'hsla(217, 97%, 62%, 0.5)',
'primary-20': 'hsla(217, 97%, 62%, 0.2)',
}),
},
},
variants: {
extend: {},
},
plugins: [],
}
This approach allows for consistent brand colors throughout your Tailwind CSS project with easy color variations and accessibility considerations.
Beyond basic styling, HSL offers powerful capabilities for modern web and app development:
Create light/dark themes by manipulating lightness values:
:root {
--primary-h: 217;
--primary-s: 97%;
--primary-l: 62%;
}
.dark-theme {
--primary-l: 40%;
--bg-l: 10%;
--text-l: 90%;
}
.light-theme {
--primary-l: 62%;
--bg-l: 95%;
--text-l: 20%;
}
Ensure WCAG compliance by adjusting lightness values:
function ensureAccessibleContrast(bgHsl, textHsl) {
// If background is light (L > 50%)
if (bgHsl.l > 50) {
// Ensure text is dark enough
return {
...textHsl,
l: Math.min(textHsl.l, 45)
};
} else {
// If background is dark, ensure text is light enough
return {
...textHsl,
l: Math.max(textHsl.l, 65)
};
}
}
Create UI controls similar to Photoshop's HSL sliders for intuitive color picking:
// React component example
function ColorPicker({ initialColor = '#3E82FC', onChange }) {
// Convert initial HEX to HSL
const [hsl, setHsl] = useState(hexToHsl(initialColor));
// Update when sliders change
const handleHueChange = (e) => {
const newHsl = { ...hsl, h: parseInt(e.target.value) };
setHsl(newHsl);
onChange(hslToHex(newHsl)); // Convert back to HEX for output
};
// Similar handlers for saturation and lightness
return (
<div className="color-picker">
<div className="color-preview" style={{backgroundColor: hslToCss(hsl)}}></div>
<div className="slider-container">
<label>Hue: {hsl.h}°</label>
<input
type="range"
min="0" max="360"
value={hsl.h}
onChange={handleHueChange}
/>
</div>
{/* Similar sliders for saturation and lightness */}
</div>
);
}
This implementation creates a color picker that behaves similarly to professional tools like Photoshop or Adobe's color pickers.
Sometimes you'll need to convert between RGB and HSL color models:
function rgbToHsl(r, g, b) {
r /= 255;
g /= 255;
b /= 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0; // achromatic
} else {
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)
};
}
// Example: converting from RGB to HSL
const color = rgbToHsl(62, 130, 252); // From #3E82FC
console.log(`hsl(${color.h}, ${color.s}%, ${color.l}%)`); // "hsl(217, 97%, 62%)"
Converting hexadecimal colors to HSL format offers numerous advantages for developers and designers: