The @media (min-width: 0\0) hack

Last updated 2016-01-12.

The hack

@media (min-width: 0\0) {
  .your-selector-here {
    /* your declarations here */
  }  
}

Sources: Browserhacks.com, Browser CSS Hacks by Paul Irish

Live testcase

Affected
Unaffected

If the square above shows the word "Affected", then your browser supports this hack.

How it works

This hack exploits a bug in the browser's parsing of CSS media queries. Backslash (\) is used as an escape character in CSS. So \0 is an escape sequence which notionally encodes the null character (␀). However, presumably to prevent bugs related to potential use of null-terminated strings in browser implementations, the CSS Syntax Module Level 3 specifically treats \0 like an invalid escape sequence and requires that it result in the Unicode replacement character (U+FFFD; "�") instead of the null character. But CSS Syntax Level 3 is a somewhat recent spec, and thus older browsers treat \0 differently.

At any rate, there are 4 obvious ways that browsers might parse 0\0:

  1. As 0�, per the CSS Syntax Level 3 spec.
  2. As 0␀, assuming the browser doesn't use null-terminated strings internally and doesn't treat null characters in CSS as syntax errors.
  3. As 0, assuming the browser does use null-terminated strings internally and doesn't treat null characters in CSS as syntax errors. To be clear, this is a blatant implementation bug in the browser.
  4. As a syntax error. Prior to CSS Syntax Level 3, this was a reasonable choice for savvy parsers, since it's difficult to come up with any legitimate use for null characters in CSS.

Cases 1 & 2 will ultimately lead to syntax errors, since neither nor are valid CSS length units, and min-width's value must be a length.

That leaves Case 3. Since zero can be unitless in valid CSS (which is allowed because 0px = 0in = 0em, etc.), the media query ends up being equivalent to @media (min-width: 0px), whose condition will always evaluate to True in any non-completely-insane browser.

Affected browsers

Check out the links for corroborating screenshots.

Test results
Chrome
OS X Safari
iOS Safari
Firefox
Microsoft Edge
Internet Explorer
Chrome OS X
Safari
iOS
Safari
Firefox MS Edge1 Internet
Explorer
48
Unknown
10
Unknown
9.3
Unknown
46
Unknown
13
Unknown
47
Unaffected
9.0.2
Unaffected
9.2
Unaffected
45.0a2
Unaffected
12.10240
Unaffected
11
Affected
46
Unaffected
8.0.8
Unaffected
8.4
Unaffected
44.0b7
Unaffected
12.10166
Unknown
10
Affected
26
Unaffected
7.1.7
Unaffected
7.1
Unaffected
43.0.4
Unaffected
9
Affected
25
Unknown
6.2.7
Unaffected
6.1
Unaffected
4.0.1
Unaffected
8
Unaffected2
5.1.7
Unknown
5.1
Unknown
7
Unknown
Note 1: MS Edge versions refer to the EdgeHTML rendering engine version, not the Edge app version shown in Edge's "About" screen. See this Can I Use issue.
Note 2: IE≤8 does not support media queries at all.