Color Converter
Convert colors bidirectionally between HEX, RGB, HSL, and CMYK formats instantly. Built entirely offline in client-side memory.
Color Space Mathematics: HEX, RGB, HSL & CMYK
A color space is a mathematical model describing the way colors can be represented as tuples of numbers. In graphic design, UI engineering, and print production, working across multiple digital and physical media requires continuous conversion between additive and subtractive color spaces.
The primary color spaces supported in modern design include:
- sRGB (Red, Green, Blue): The standard additive color model for electronic displays (0â255 per channel). Red, green, and blue light combine to produce pure white.
- HEX (#RRGGBB): Base-16 hexadecimal shorthand for sRGB channels (e.g.
#6366F1), ubiquitous in CSS stylesheets and UI design tokens. - HSL (Hue, Saturation, Lightness): A cylindrical coordinate representation of RGB that aligns closely with human perception. Hue is an angle (0°â360° on the color wheel), Saturation is a percentage (0% gray to 100% vivid), and Lightness represents illumination (0% black to 100% white). HSL is ideal for generating programmatic color palettes and hover states.
- CMYK (Cyan, Magenta, Yellow, Key/Black): The subtractive color model used in commercial color printing presses. Inks absorb light; combining cyan, magenta, and yellow subtracts reflected light toward black.
Our Color Converter translates colors across all spaces simultaneously, calculating WCAG contrast ratios and one-click CSS code copies.
Programmatic Color Space Conversion in JavaScript
// Convert HEX to RGB
function hexToRgb(hex) {
const cleanHex = hex.replace(/^#/, '');
const num = parseInt(cleanHex, 16);
return {
r: (num >> 16) & 255,
g: (num >> 8) & 255,
b: num & 255
};
}
// Convert RGB to HSL
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), 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) };
}
console.log(hexToRgb("#6366F1")); // { r: 99, g: 102, b: 241 }
console.log(rgbToHsl(99, 102, 241)); // { h: 239, s: 84, l: 67 }
WCAG 2.1 Color Contrast & Accessibility Standards
Web Content Accessibility Guidelines (WCAG) 2.1 establish strict minimum color contrast ratios between text and background to ensure readability for users with low vision or color blindness:
- Level AA (Minimum Requirement): Requires a contrast ratio of at least 4.5:1 for normal text, and 3.0:1 for large text (18pt or 14pt bold).
- Level AAA (Enhanced Accessibility): Requires a contrast ratio of at least 7.0:1 for normal text, and 4.5:1 for large text.
Next-Gen CSS Color Spaces: OKLCH & Display P3
CSS Color Module Level 4 introduces modern perceptual spaces like OKLCH and Display P3. OKLCH fixes long-standing visual luminance bugs in HSL, ensuring that colors with identical lightness values appear equally bright to human eyes across all hues.
Related Converters & Encoders
Chain Color Converter with these complementary client-side utilities from our Converters & Encoders collection:
Convert HTML code snippets to clean Markdown syntax instantly. Free online client-side tool. Includes support for lists, tables, headers, and code blocks.
Free online Roman Numeral converter. Instantly translate numbers to Roman numerals and Roman numerals to numbers (1-3999) offline. Private and secure.
Encode URL query parameters or decode percent-escaped URLs into readable strings instantly. 100% private, client-side, and supports safe query encoding.
Convert plain text to Base64 format or decode Base64 strings to readable text instantly. 100% private, browser-based, and supports UTF-8.
Frequently Asked Questions
RGB is an emissive light model with a wide gamut of bright neon colors. CMYK is a reflective ink model with a narrower physical color gamut; some vivid RGB colors cannot be physically reproduced with printing inks.
The alpha channel specifies opacity, ranging from 0.0 (completely transparent) to 1.0 (completely opaque).
With HSL, keep the Hue and Saturation identical, and simply reduce the Lightness percentage by 10% to 15% (e.g. hsl(240, 80%, 50%) becomes hsl(240, 80%, 40%)).
Yes. Shorthand hex codes are automatically expanded to full 6-digit representations (#ffffff).
Yes. All transformations are computed locally using client-side JavaScript.