8-digit hex is not a background-color value

Viewed 1601

I am using the W3 CSS validator and when trying to validate my code it finds these errors:

121 thead Value Error : background-color #e422357a is not a background-color value : #e422357a 125 tbody Value Error : background-color #1515157a is not a background-color value : #1515157a 129 tfoot Value Error : background-color #e8b63d7a is not a background-color value : #e8b63d7a

This is the code in question. This is for a school assignment and my professor told me it's important that I validate my code, but I can't seem to figure out what is wrong with it?

Aren't 8 digit hex colors valid background colors?

thead {
    background-color: #e422357a;
}

tbody {
    background-color: #1515157a;
}

tfoot {
    background-color: #e8b63d7a;
}
2 Answers

The Jigsaw W3C CSS validator isn't known for being up to date with developing standards, such as most level 4 CSS features. New features are being introduced and implemented faster than they can be standardized or validators can catch up, so validation has become increasingly unreliable as anything other than a sanity check for potential careless mistakes, rather than traditional standards-compliance "certification" (if you will).

As long as you use the notation with the understanding that browser support isn't complete and these drafts are subject to change (although support for this notation is extremely unlikely to change), you'll be fine.

If you are concerned about validation, your best bet is to rewrite these values to their rgba() counterparts, which enjoy cross-browser support and are recognized by Jigsaw.

As clarified by Temani Afif below, your code is OK, but the validator is not recognizing it. As this appears to be homework, I'd suggest that you use a 3 byte code (unless a project requirement mandates it), but understand that your code is truly valid. Remember that the tools you used may be the tools your instructor uses and they may take that at face value without digging deeper. I'd have to double-check the spec, but use 3 byte codes, instead. The 4th byte is used for the alpha (transparency) channel and isn't being recognized by the validator.

To elaborate, color can be specified by the below means.

You've specified RGBA, but the validator doesn't like it. Ditch the 4th byte or use a validator that will recognize truly compliant code.

Edit: Try W3's own validation service.

Related