Methodology
Color methodology
sRGB throughout. HEX, RGB, HSL, HSV are different labels for the same colour.
The Color cluster handles conversions between four representations of the same underlying colour: HEX (#FF6B35), RGB (255, 107, 53), HSL (16°, 100%, 60%), and HSV (16°, 79%, 100%). All four describe a colour in the same colour space — sRGB — so the conversions are algebraic relabelings, not perceptual remappings.
sRGB as the universal anchor
sRGB (Standard RGB) is the default colour space of the web, defined by the IEC 61966-2-1 standard in 1999. It specifies the exact red, green, and blue primaries that combine to produce any displayable colour, plus a non-linear gamma curve approximating the response of a typical CRT monitor. Modern LCDs and OLEDs emulate this curve.
Every HEX colour, every rgb(…) value, every CSS-default hsl(…) assumes sRGB unless otherwise tagged. Newer wide-gamut formats (Display P3, Rec.2020) exist but require explicit opt-in via color(display-p3 …)or similar — outside this cluster’s scope.
The conversion math
HEX ↔ RGB
Direct base conversion: each pair of hex digits is one byte (0-255). #FF6B35 ↔ rgb(255, 107, 53) exactly, no precision loss. Three-digit hex (#F63) is the shorthand for #FF6633.
RGB → HSL
Convert R, G, B to the range [0, 1]. Find the max and min channels. Lightness L = (max + min) / 2. Saturation depends on whether L < 0.5 or not. Hue is computed from which channel is the max and the relative differences between channels.
The full formula is standard and is implemented exactly in our library. Hue is reported in degrees [0, 360); saturation and lightness in percent [0, 100].
RGB → HSV
Similar logic. Value V = max. Saturation S = (max − min) / max when max ≠ 0. Hue is identical to the HSL hue.
HSL and HSV diverge on the saturation axis. A colour at 100% HSV saturation is fully saturated; at 100% HSL saturation it’s fully saturated only at L = 0.5. Designers prefer HSL for adjusting tints and shades; image editors often expose HSV (Photoshop calls it “HSB” for “brightness”).
Round-trip precision
HEX ↔ RGB is bit-exact. Either direction round-trips losslessly.
RGB ↔ HSL / RGB ↔ HSV involve floating-point arithmetic. Round-trip precision is bounded by the 8-bit RGB output — the worst case rounds a channel by ±1 out of 255 (about 0.4%). Display-wise this is invisible; for colour-critical work avoid the round-trip if you can.
What we don’t handle
- Wider-gamut spaces (P3, Rec.2020) — out of scope.
- Perceptually-uniform spaces (Lab, LCH, Oklab) — sometimes asked for; the algebra is more involved. May ship as a separate tool later.
- CMYK — print-specific colour space; conversions require ICC profiles, not just algebra. See our RGB vs CMYK comparison.
- Alpha — RGB→HSL/HSV preserve alpha as a passthrough. HEX with alpha (#RRGGBBAA) is supported.
Related
Published May 14, 2026