CSS: the Underscore hack is not valid

The CSS Underscore hack (and its variants) is widely used, though many developers don't actually know that this particular CSS pattern raises a validation error. Let's see the details.

The Underscore hack

This hack is used in order to deliver style rules only to Internet Explorer 6 (and lower). It relies on a different interpretation of the CSS specifications which allow browsers to use an underscore (_) or hyphen (-) as a prefix for a vendor-specific property name. However, the CSS specifications state also that such properties will never be used in a future CSS standard. In other words, these vendor-specific properties are not valid CSS property and thus this hack won't validate. The pattern is the following:

p {_color: red;}

A variant of this pattern is now used to target also Internet Explorer 7. The pattern is the following:

p {*color: red;}

Validation output:

Property _color doesn't exist : red Parse Error {*color: red}

So if you want to use this hack, you should put it inside a conditional comment.

Back to top