isCssColor
Commons
stable
Type guard that returns true when the input string is a valid CSS color value: a hex code, a functional notation (rgb, hsl, hwb, lab, lch, oklab, oklch, color), a CSS variable (var(--…)), or one of the 148 named CSS colors.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- colorstring | null | false
- The value to test. Falsy values (null, undefined, false, empty string) return false.
API
Return value
The value returned by this util.
- true when the string matches a recognised CSS color format; false for intent strings like "primary" or non-color values.
Usage
Examples
Ready-to-paste usage snippets.
Distinguish raw CSS colors from intent tokens