Color Space Converter
Convert colors between HEX, RGB, HSL, HSV, CMYK, HWB, LAB, LCH and CSS named colors. Live preview, palette generation, and one-click copy.
About
Color space conversion is non-trivial. A naive HEX-to-RGB parser ignores gamma correction entirely. Converting to perceptual spaces like CIE LAB requires linearizing sRGB values, transforming through the CIE XYZ intermediate space with the D65 illuminant matrix, then applying a cube-root companding function. Get any step wrong and your L* lightness value drifts by 5 - 15 units, enough to break accessibility contrast checks. CMYK conversion without a device ICC profile is inherently an approximation; this tool uses the standard formulaic approach where K = 1 − max(R′, G′, B′). It will not match a Pantone swatch book.
This converter parses any valid CSS color string, including all 148 named colors, and outputs precise values across 8 color spaces simultaneously. It calculates WCAG 2.1 relative luminance and contrast ratios against white and black backgrounds so you can verify AA and AAA compliance on the spot. Palette harmonies (complementary, analogous, triadic, split-complementary) are computed via hue rotation in HSL space. Note: LAB and LCH values assume the sRGB gamut and D65 standard illuminant. Colors outside sRGB gamut cannot be represented.
Formulas
The sRGB-to-CIE-LAB pipeline proceeds through three transformations. First, each sRGB channel is linearized by removing gamma companding:
where CsRGB is each channel (R, G, or B) normalized to [0, 1]. Next, linear RGB is transformed to CIE XYZ (D65 illuminant) via the standard 3×3 matrix:
Finally, XYZ is converted to LAB using the D65 reference white (Xn = 0.95047, Yn = 1.00000, Zn = 1.08883):
where the transfer function f(t) applies a cube root for values above the threshold δ = 6÷29:
LCH is the polar form of LAB: C* = √a*2 + b*2 and h = atan2(b*, a*). HSL conversion uses the standard min/max channel decomposition. CMYK is computed as K = 1 − max(R′, G′, B′), with C = (1 − R′ − K) ÷ (1 − K) and analogously for M and Y. WCAG relative luminance: L = 0.2126Rlin + 0.7152Glin + 0.0722Blin.
Reference Data
| Color Space | Channels | Ranges | Gamut | Perceptual Uniformity | Common Use |
|---|---|---|---|---|---|
| sRGB | R, G, B | 0 - 255 (integer) | sRGB | No | Web, screens, CSS |
| HEX | R, G, B (base-16) | 00 - FF | sRGB | No | CSS shorthand |
| HSL | H, S, L | 0 - 360°, 0 - 100%, 0 - 100% | sRGB | No | CSS, design tools |
| HSV/HSB | H, S, V | 0 - 360°, 0 - 100%, 0 - 100% | sRGB | No | Photoshop, color pickers |
| CMYK | C, M, Y, K | 0 - 100% | Device-dependent | No | Print production |
| HWB | H, W, B | 0 - 360°, 0 - 100%, 0 - 100% | sRGB | No | CSS Level 4 |
| CIE LAB | L*, a*, b* | 0 - 100, ≈−128 - 127 | Unbounded (human vision) | Yes (approximately) | Color science, ΔE comparison |
| CIE LCH | L*, C*, h | 0 - 100, 0 - 150+, 0 - 360° | Unbounded | Yes | Perceptual palettes |
| CSS Named | keyword | 148 names | sRGB | N/A | Quick CSS authoring |
| RGBA | R, G, B, α | 0 - 255, 0 - 1 | sRGB | No | Transparent overlays |
| HSLA | H, S, L, α | same as HSL + 0 - 1 | sRGB | No | CSS transparency |
| Linear RGB | R, G, B | 0 - 1 (float) | sRGB (linear) | No | Intermediate for XYZ |
| CIE XYZ | X, Y, Z | 0 - 1 (approx) | Unbounded | No | Color science pipeline |