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]

– Jeff Clayton's Live CSS hacks and tests to filter for mainstream browsers, including the only known CSS Hacks for Safari 7 and 8

Browser Strangeness

– Multiple browser filter methods and tests (Hugo Giraudel, Joshua Hibbert, Tim Pietrusky, Fabrice Weinberg, Jeff Clayton)

browserhacks.com

refix filters]

Safari/Webkit (webkit) prefix filters

Mozilla (moz) prefix filters

– This page has all of Opera's CSS selectors.

Opera (wap) prefix filters

– A fairly complete table of CSS hacks which show and hide rules from specific browsers.

CSS Filters

– CSS filters. Parsing errors marked red.

Filters and Cross-Over

– Allows to combine browser specific CSS in single stylesheet (using JavaScript).

– CSS Browser Selector

– Targeting IE with a single stylesheet containing all CSS (without using JavaScript, but using conditional comments to assign browser-specific tag to arbitrary content root <div>)

– #IEroot

– discussion on StackOverflow

How to target only IE (any version) within a stylesheet?

– discussion on StackOverflow

Apply style ONLY on IE

- How to add comments in CSS

CSS Comments