Types of hacks[edit]
Invalid or non-compliant CSS[edit]
Due to quirks in the interpretation of CSS by various browsers, most CSS hacks involve writing invalid CSS rules that are interpreted only by specific browsers, or relying on bugs in specific browsers. An example of this is prefixing rules with an underscore (as in _width
) to target Internet Explorer 6—other browsers will ignore the line, allowing it to be used to write code specific to one browser.
Similar CSS hacks involve inducing syntax errors like asterisks, missing whitespace, and CSS comments around property names. Additionally, in Internet Explorer 6 and 7, the !important
declaration is recognized as such with any string after the exclamation mark, e.g. !ie
.[1]
Unsupported CSS[edit]
Although newer CSS rules are correct by current standards, they are ignored by older browsers as "invalid". By writing old rules followed by newer rules that cancel out or modify the old ones, it is possible to only activate certain rules on older browsers.
Alternatives[edit]
Browser prefixes[edit]
Each of the most popular browser rendering engines has its own vendor prefix for experimental properties. However, due to the proliferation of these properties in live code, the browser vendors have begun moving away from this practice in favor of feature flags.[2]