Colour Code Validator
DataValidate any colour code — HEX, RGB, RGBA, HSL, or HSLA — instantly. Checks syntax and value ranges. Free, client-side, no sign-up required.
What is a Colour Code?
A Colour Code Validator checks whether a CSS colour value is correctly formatted and all channel values are within their valid ranges. Web colours are expressed in several formats — hexadecimal (#HEX), RGB, RGBA, HSL, and HSLA — each with specific syntax rules and numeric constraints. A single typo in a colour code causes the browser to silently fall back to a default, which can break visual designs in ways that are difficult to spot without careful inspection.
HEX is the most common format: a # symbol followed by 3, 4, 6, or 8 hexadecimal digits representing red, green, blue, and optionally alpha (transparency) channels. RGB notation uses decimal integers (0–255) per channel. HSL describes colours in terms of hue (0–360 degrees on the colour wheel), saturation (0–100%), and lightness (0–100%), which many designers find more intuitive for creating colour palettes.
This validator checks format and value ranges for all five CSS colour function types. It accepts both uppercase and lowercase hex digits, and strips common formatting variations. Where a value is structurally correct but a channel is out of range (e.g. rgb(300, 0, 0)), it gives a specific error rather than a generic failure.
If you are generating colour values programmatically, you may also find the Colour Converter useful for converting between HEX, RGB, and HSL representations.
How to use this Colour Code calculator
- Copy a colour code from your CSS file, design tool, or colour picker.
- Paste it into the Colour Code input field.
- The validator runs instantly — no button press needed.
- Check the Valid / Invalid badge.
- If valid, the format and any noteworthy details (alpha channel, expanded HEX) are shown below.
- If invalid, read the specific error message and correct the format accordingly.
Formula & Methodology
Each format is validated against a dedicated regular expression: | Format | Pattern (simplified) | Valid range | |---|---|---| | #RGB |#[0-9a-f]{3}| Any 3 hex digits | | #RRGGBB |#[0-9a-f]{6}| Any 6 hex digits | | #RGBA |#[0-9a-f]{4}| Any 4 hex digits | | #RRGGBBAA |#[0-9a-f]{8}| Any 8 hex digits | | rgb() |rgb(r, g, b)| r, g, b: 0–255 | | rgba() |rgba(r, g, b, a)| r, g, b: 0–255; a: 0–1 | | hsl() |hsl(h, s%, l%)| h: 0–360; s, l: 0–100 | | hsla() |hsla(h, s%, l%, a)| h: 0–360; s, l: 0–100; a: 0–1 | Valid example:#2F6FED— 6-digit HEX, all characters are valid hex digits ✓ Invalid example:rgb(300, 0, 0)— red channel value 300 exceeds the maximum of 255 ✗