Static Validation Checks
Validate CSS named colors and hex, RGB, and HSL formats using the Color class.
Color Format Checkers
Note
Please refer to the color types here: Color Types to understand the color types used in the examples below.
For individual checker functions, consider using the standalone Checker Functions.
isHex6()
Validates if a string is a valid 6-character hex color.
Signature
static isHex6(color: string): color is Hex6Parameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid Hex6.
Example
isHex8()
Validates if a string is a valid 8-character hex color (with alpha channel).
Signature
static isHex8(color: string): color is Hex8Parameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid Hex8.
Example
isRGB()
Validates if a string matches the standard solid rgb() color format.
Signature
static isRGB(color: string): color is RGBParameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid RGB.
Example
isRGBA()
Validates if a string matches the alpha rgba() color format.
Signature
static isRGBA(color: string): color is RGBAParameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid RGBA.
Example
isHSL()
Validates if a string matches the standard solid hsl() color format.
Signature
static isHSL(color: string): color is HSLParameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid HSL.
Example
isHSLA()
Validates if a string matches the alpha hsla() color format.
Signature
static isHSLA(color: string): color is HSLAParameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif valid HSLA.
Example
Validation Rules
Hex Formats
- Hex6: Exactly 6 hexadecimal characters after
#. - Hex8: Exactly 8 hexadecimal characters after
#(includes alpha).
RGB/RGBA Formats
- Red, Green, Blue: Must be between 0-255 (inclusive).
- Alpha: Must be between 0-1 (inclusive).
HSL/HSLA Formats
- Hue: Must be between 0-360 (inclusive).
- Saturation: Must be between 0-100% (inclusive).
- Lightness: Must be between 0-100% (inclusive).
- Alpha: Must be between 0-1 (inclusive).
isCSSColor()
Validates if a string is a valid CSS named color.
Signature
static isCSSColor(color: string): color is CSSColorParameters
| Parameter | Type | Description |
|---|---|---|
color | string | The string to validate. |
Returns
boolean:trueif a valid CSS color name.
Example
Last updated: Mon, Jun 15, 2026 09:49:35PM (UTC)
