Color Helpers
Utility functions for working with color operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
argbToRgb | Converts a 32-bit packed ARGB integer (as used by e.g. |
hexToRgb | Parses a hex color string (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` — the leading `#` is optional) into its RGB(A) chann… |
hslToRgb | Converts 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 / darken | native JS color-mix(in oklch, <color> <percent>, white|black) (CSS Color 5 (Baseline widely available since 2023 — Chrome 111, Firefox 113, Safari 16.2)) |
rgbToHex | Converts an RGB(A) color into a hex color string. |
rgbToHsl | Converts 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+)) |
