[X]

Star HTML and the Underscore Hack

layout hacks 2003 partly

CSS aimed at one browser by exploiting a bug in how it parsed the selector.

In 2026: The selectors are still valid CSS so nothing errors, they just match nothing now. IE6 and below invented a phantom element above HTML, so * html matched only there. The underscore and star prefixes worked because IE ignored the leading character.

Where it came from: Widely circulated on css-discuss and A List Apart, roughly 2001 to 2005.
Wikipedia Wayback: Position Is Everything

<style>
/* Everyone */
.box { height: 100px; margin-left: 20px; }

/* IE6 and below only: they behave as if something wraps HTML */
* html .box { height: 120px; }

/* IE7 and below only */
*+html .box { height: 110px; }

/* IE6 only, inside a normal rule. Valid browsers drop the property. */
.box { width: 300px; _width: 320px; }

/* IE7 and below only, same trick with a star */
.box { padding: 10px; *padding: 12px; }
</style>

<div class="box" style="border:2px solid #333;background:#cfe;font:13px Verdana">
  A box the rules above all target. In a current browser only the plain rules
  apply, so nothing about it is hacked: the IE-only selectors match nothing.
</div>

<!-- The 2026 version: nothing. These browsers are gone. -->
sandboxed demo · breaks nothing but itselfrestart

More in layout hacks

view the whole library ›