Skip to content

color

Validates that a field contains a valid CSS color value.

Options

OptionTypeDefaultDescription
typestring | string[]allAccepted color format(s): "hex", "rgb", "rgba", "hsl", "hsla", "keyword", or "all"
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
"#FF5733"Hex color
"rgb(255, 87, 51)"RGB
"hsl(9, 100%, 60%)"HSL
"red"CSS color keyword

Invalid values

ValueReason
"notacolor"Not a recognized CSS color format
"#GGHHII"Invalid hex digits

Notes

  • Empty string ("") always returns valid: true. Combine with notEmpty to require a value.
  • type can be a single string ("hex") or an array (["hex", "rgb"]).

Released under the MIT License.