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.
Reviewed by the thecalcu.com team · Last updated July 31, 2026
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.
Why Use a Colour Code Validator?
Colour code errors are silent, a browser encountering an invalid CSS colour simply ignores the property. In large design systems or theme files with hundreds of colour tokens, one malformed value can cause a component to render with the wrong colour or no colour at all, and the only symptom is a visual regression.
Common mistakes include: missing the # prefix on a hex code, using 5 or 7 hex digits instead of 3, 4, 6, or 8, using an RGB channel value above 255 (e.g. copy-pasting a 0–100 percentage scale), or using commas in HSL values without the percentage sign on saturation and lightness.
This validator catches all of these before they reach production.
Who Should Use This Validator?
Front-end developers and UI engineers, validate design tokens, theme variables, and hardcoded colour values in CSS/SCSS before committing.
Designers exporting colour palettes, verify that HEX codes copied from design tools (Figma, Adobe) are complete and correctly formatted before handing off to engineering.
No-code and low-code builders, confirm that colour codes entered into CMS theme editors or site builders are valid before publishing.
QA engineers, automate colour code validation as part of design-token regression checks in CI pipelines.
What Insights Does the Colour Code Validator Give You?
For a valid colour, the tool identifies the format (HEX shorthand, HEX full, RGB, RGBA, HSL, HSLA), confirms all channel values are in range, and notes the alpha channel if present. For 3-digit HEX codes, it shows the equivalent 6-digit expanded form.
For an invalid colour, it explains the specific problem: wrong digit count for a HEX code, out-of-range channel values, unrecognised format, or non-hexadecimal characters. This is more useful than a plain "Invalid" because it points directly to what needs fixing.
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 ✗
Related Tools
You may also find these useful: URL Validator, Regex Tester.
Frequently Asked Questions