Error Invalid hex color value

The valid hex color lengths (3, 4, 6, 8 digits) and why other lengths aren't valid CSS colors.

The validator flags any #-prefixed color value whose digit count isn't 3, 4, 6, or 8.

Example

/* Wrong: 5 digits isn't a valid length */
color: #1a2b3;

/* Valid lengths */
color: #1a2;         /* 3 digits — shorthand RGB */
color: #1a2f;         /* 4 digits — shorthand RGB + alpha */
color: #1a2b3c;       /* 6 digits — full RGB */
color: #1a2b3cff;     /* 8 digits — full RGB + alpha */

Why it matters

Hex colors pack red, green, and blue (and optionally alpha) into pairs — or single shorthand digits — of hex characters, so the total length has to divide evenly into those 3 or 4 channels. A 5-digit value like #1a2b3 can't be split evenly and isn't valid CSS at all; browsers discard the entire declaration it appears in, silently, rather than guessing at what you meant. This is usually a typo — a digit dropped or added while editing — rather than a deliberate choice.

Frequently asked questions

What happens when a browser hits an invalid hex color?

The browser drops the entire declaration as invalid — the property simply doesn't apply, falling back to whatever it would inherit or default to. There's no visible error, which is why these typos are easy to miss.

What's the difference between 3-digit and 6-digit hex?

3-digit is shorthand where each digit is doubled — #1a2 expands to #11aa22. It's a convenient shorthand only when each channel happens to be a repeated digit; anything else needs the full 6-digit form.