Conversions
HEX ↔ RGB / HSL / HSV
hexToRgb(hex)
[r, g, b] — an RGB component tuple, each 0–255
Converts a HEX color (#rgb or #rrggbb, # optional, case-insensitive) into RGB components.
hexToRgba(hex, opacity)
string — an rgba(r, g, b, opacity) string
Converts a HEX color into a CSS rgba(...) string at the given opacity (0–1, defaults to 1).
hexToHsl(hex)
[h, s, l] — hue 0–360°, saturation and lightness 0–100%
Converts a HEX color into HSL components.
hexToHsv(hex)
[h, s, v] — hue 0–360°, saturation and value 0–100%
Converts a HEX color into HSV components.
hslToHex(h, s, l)
string — a #rrggbb color
Converts HSL into a HEX color. h wraps into 0–360; s/l are clamped to 0–100.
hsvToHex(h, s, v)
string — a #rrggbb color
Converts HSV into a HEX color.
RGB ↔ HSL / HSV / HWB
rgbToHsl({r, g, b})
[h, s, l] — hue 0–360°, saturation and lightness 0–100%
Converts RGB components (each 0–255) into HSL components.
hslToRgb(h, s, l)
{ r, g, b } — RGB components, each 0–255
Converts HSL into an RGB object.
rgbToHsv({r, g, b})
[h, s, v] — hue 0–360°, saturation and value 0–100%
Converts RGB into HSV components.
hsvToRgb(h, s, v)
{ r, g, b } — RGB components, each 0–255
Converts HSV into an RGB object.
rgbToHwb({r, g, b})
[H, W, B] — hue 0–360°, whiteness and blackness 0–100%
Converts RGB into HWB components.
hwbToRgb(H, W, B)
{ r, g, b } — RGB components, each 0–255
Converts HWB into an RGB object. W/B are whiteness and blackness 0–100 — a combined total ≥ 100 yields a gray.
RGB ↔ HEX / RGBA strings
rgbToHex({r, g, b})
string — a #rrggbb color (lowercase)
Converts RGB into a HEX color.
rgbaToHex({r, g, b, a})
string — a #rrggbbaa color
Converts RGBA (alpha a in the 0–1 range) into an 8-digit HEX color with the alpha channel appended.
rgbaToHex8({r, g, b, a})
string — a #rrggbbaa color
Alias for rgbaToHex — identical behavior under a more explicit name.
rgbToRgbaString({r, g, b}, a)
string — an rgba(r, g, b, a) string (alpha rounded to 3 decimals)
Builds a CSS rgba(...) string from RGB components and a separate alpha argument.
RGB ↔ CMYK
rgbToCmyk({r, g, b})
{ c, m, y, k } — CMYK components in the 0–1 range (not percentages)
Converts RGB into CMYK components.
cmykToRgb({c, m, y, k})
{ r, g, b } — RGB components, each 0–255
Converts CMYK (components in the 0–1 range) into an RGB object.
RGB ↔ Lab / LCH / Oklab / Oklch
rgbToLab({r, g, b})
{ L, a, b } — CIE Lab (D65): lightness, the green↔red axis, and the blue↔yellow axis
Converts RGB into CIE Lab via an intermediate XYZ space.
labToRgb({L, a, b})
{ r, g, b } — RGB components, each 0–255
Converts CIE Lab coordinates back into an RGB object.
rgbToLch({r, g, b})
{ L, C, H } — lightness, chroma (saturation), and hue angle in degrees
Converts RGB into CIE LCH — the cylindrical representation of Lab.
lchToRgb({L, C, H})
{ r, g, b } — RGB components, each 0–255
Converts CIE LCH coordinates back into an RGB object.
rgbToOklab({r, g, b})
{ L, a, b } — Oklab: lightness (≈0–1) and two color axes
Converts RGB into the perceptually uniform Oklab space.
oklabToRgb({L, a, b})
{ r, g, b } — RGB components, each 0–255
Converts Oklab coordinates back into an RGB object.
rgbToOklch({r, g, b})
{ L, C, H } — lightness, chroma, and hue angle in degrees
Converts RGB into Oklch — the cylindrical representation of Oklab.
oklchToRgb({L, C, H})
{ r, g, b } — RGB components, each 0–255
Converts Oklch coordinates back into an RGB object.
RGB ↔ Display P3
rgbToDisplayP3({r, g, b})
{ r, g, b } — components in the Display P3 space, each in the 0–1 range
Converts sRGB components (each 0–255) into the wider Display P3 color space (linearize → transform matrix → gamma encode).
displayP3ToRgb({r, g, b})
{ r, g, b } — sRGB components, each 0–255
Converts Display P3 components (each in the 0–1 range) back into sRGB.
toDisplayP3Hex(color)
string — a HEX string
Converts an arbitrary color (HEX, rgb(), hsl(), etc.) through the Display P3 space and returns the result as HEX.