Methodology
Color methodology
sRGB throughout. HEX, RGB, HSL, HSV are different labels for the same colour.
By Buğra SözeriPublished Updated
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.
Algorithm details: HSL and HSV in full
The conversion library ships these formulas verbatim; they’re reproduced here so the algebra is visible. Normalised inputs R, G, B ∈ [0, 1] with M = max(R, G, B), m = min(R, G, B), chroma C = M − m:
L = (M + m) / 2S_HSL = C / (1 − |2L − 1|) if C ≠ 0, else 0V = MS_HSV = C / M if M ≠ 0, else 0
Hue is the same axis in both models:
H = 60° × ((G − B) / C mod 6) if M = RH = 60° × ((B − R) / C + 2) if M = GH = 60° × ((R − G) / C + 4) if M = B
The sRGB linearisation, applied when computing luminance for contrast or interpolating perceptually, is the piecewise transfer from IEC 61966-2-1: linear = c/12.92 if c ≤ 0.04045, else ((c + 0.055)/1.055)^2.4. Round-tripping through linear and back is bit-exact for the 8-bit sRGB grid because the piecewise inverse is well-defined.
Sources & references
Every formula on this page is from a primary spec or a peer-reviewed publication: sRGB primaries and gamma from IEC 61966-2-1, CSS hex/rgb/hsl syntax from W3C CSS Color Module Level 4, RGB↔HSV conversion from Smith’s 1978 paper, contrast formula from WCAG 2.2. The Sources block at the foot of this page lists the publicly-available versions used as ground truth during library testing.
Assumptions & limitations
- sRGB throughout.Inputs without an explicit colour-space tag are assumed sRGB. P3 / Rec.2020 / Adobe RGB inputs aren’t auto-detected and would be misinterpreted if passed as raw RGB.
- 8-bit integer RGB. Hex input clamps to [0, 255] per channel. 10- or 12-bit HDR pipelines need a wider format than #RRGGBB.
- HSL/HSV are convenience reparameterisations, not perceptual spaces.Equal numeric changes in H, S, or L don’t map to equal perceptual changes — use OKLCH or CIELAB for perceptually-uniform work.
- No chromatic adaptation.Converting across spaces with different white points (D65 ↔ D50) requires a Bradford or CAT02 transform we don’t apply.
- CMYK requires ICC profiles.Algebraic CMYK ≈ RGB approximations on the web are uniformly wrong for print; we don’t emit a CMYK value at all.
- Alpha is passthrough, not premultiplied.Round-tripping through HSL/HSV preserves the alpha channel but doesn’t apply the alpha to the colour components.
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.
Frequently asked questions
- What color space does Convertitive use?
- All conversions use sRGB (IEC 61966-2-1:1999) as the canonical color space. HEX, RGB, HSL, and HSV are all different coordinate representations of the same sRGB gamut — converting between them is lossless. Wide-gamut spaces (Display P3, Rec. 2020) are not currently supported; values are always assumed to be sRGB.
- What formula does Convertitive use for RGB ↔ HSL conversion?
- The standard algorithm from Foley & van Dam (Computer Graphics: Principles and Practice, 1990). Given normalized RGB (r, g, b ∈ [0,1]): L = (max + min) / 2; S = (max − min) / (1 − |2L − 1|) when L ≠ 0 or 1; H is computed from which channel is max and the relative distances between channels. The inverse uses the same c = (1 − |2L − 1|) × S chroma term and the six-sector hue-to-RGB mapping.
- How accurate is the HEX ↔ RGB conversion?
- Exact and lossless. A HEX code like #FF6B35 maps to rgb(255, 107, 53) by simple base-16 decoding of each byte pair — no floating-point involved. The only precision loss happens when converting to HSL or HSV, which use floating-point division and round-trip back to 8-bit integers with ±1 unit rounding error in extreme cases.
- What are the limitations of the color converter?
- Three main limitations: (1) sRGB-only — Display P3 or OKLCH wide-gamut values are not supported; (2) 8-bit per channel — HDR or 10-bit color representations are out of range; (3) HSL/HSV are achromatic (undefined hue) when S = 0, so the converter displays H = 0 for greys, consistent with CSS Color Level 4 §4.2.
- Where does the relative luminance formula come from?
- The relative luminance formula L = 0.2126 R + 0.7152 G + 0.0722 B (with linearisation via the sRGB transfer function) is defined in WCAG 2.2 §1.4.3 (and its normative reference ICC.1:2010). It is used downstream to compute WCAG contrast ratios. The coefficients reflect the sensitivity of the human visual system to the sRGB primaries as defined in ICC.1:2010.
Sources & references
Authoritative references cited by this piece. Verified by Buğra Sözeri on the dates shown and re-checked at every deploy.
- IEC 61966-2-1:1999 — Multimedia systems and equipment — Colour measurement and management — Default RGB colour space — sRGB — The international standard defining the sRGB primaries, white point, and piecewise transfer function our converter assumes throughout.(as of )
- W3C CSS Color Module Level 4 — Defines the canonical CSS hex/rgb/hsl/hwb/lch syntax and the gamut-mapping rules wide-gamut clients apply to sRGB output.(as of )
- Smith (1978) — Color Gamut Transform Pairs — The original peer-reviewed publication of the RGB↔HSV conversion algorithm our converter implements.(as of )
- International Color Consortium — ICC.1:2010 (Profile Format) — Defines the ICC profile structure underpinning the CMYK / wide-gamut conversions we deliberately don’t attempt in-browser.(as of )
- WCAG 2.2 — Contrast (Minimum) — Defines the relative-luminance formula used for accessibility-contrast computations downstream of our sRGB output.(as of )
Related
Published May 14, 2026 · Last reviewed May 31, 2026