Hex Color Validator
Validate whether a string is syntactically correct hex color notation (3, 4, 6, or 8 digits), with a specific explanation of what's wrong if invalid.
How to Use the Hex Color Validator
Type any string into the box, and the tool checks whether it's syntactically correct hex color notation. Valid hex colors have 3, 4, 6, or 8 hex digits (0-9 and A-F), with or without a leading #. If the value is invalid, the tool explains exactly what's wrong — whether it's the wrong digit count, invalid characters, or something else.
Example
#3B82F6 is valid (6 digits). #fff is valid (3-digit shorthand). #ff00ff80 is valid (8 digits, includes alpha). #12345 is invalid (5 digits — not one of the allowed lengths). #gggggg is invalid (contains the character "g", which isn't a valid hex digit).
Common Use Cases
- Checking a hex color value pasted from an external source before using it in code.
- Debugging why a CSS color isn't rendering — often due to an invalid hex format.
- Validating user-submitted color values in a form before saving them.
FAQs
- What hex digit counts are considered valid? 3 digits (shorthand RGB), 4 digits (shorthand RGB with alpha), 6 digits (full RGB), or 8 digits (full RGB with alpha) — any other count is flagged as invalid.
- Is the leading "#" required? No — the tool accepts hex values both with and without a leading "#" symbol, since both forms are commonly used depending on context.
- What characters are valid in a hex color? Only the digits 0-9 and the letters A-F (case-insensitive) — any other character, including spaces or symbols, makes the value invalid.
