Skip to content

Color Helpers

Utility functions for working with color operations.

FunctionDescription
argbToRgbConverts a 32-bit packed ARGB integer (as used by e.g.
hexToRgbParses a hex color string (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` — the leading `#` is optional) into its RGB(A) chann…
hslToRgbConverts an HSL(A) color into RGB(A).
isLight / isDark (pick a readable text color)native JS contrast-color(<color>) (CSS Color 6 (Baseline newly available since April 2026 — Chrome 147, Firefox 146, Safari 26.0))
lighten / darkennative JS color-mix(in oklch, <color> <percent>, white|black) (CSS Color 5 (Baseline widely available since 2023 — Chrome 111, Firefox 113, Safari 16.2))
rgbToHexConverts an RGB(A) color into a hex color string.
rgbToHslConverts an RGB(A) color into HSL(A).
withAlpha (change the alpha channel of an existing color)native JS rgb(from <color> r g b / <alpha>) (CSS Color 5 relative color syntax (Baseline widely available since September 2024 — Chrome 119+))