razorborg essays

Modernizr, IE8, X-UA-Compatible, and Standards Mode

September 24, 2013 by Jan Martin Borgersen

Here’s a quick tip for folks using Modernizr for client browser detection (or any other script that puts comment blocks around your HTML tag), and you need to ensure that that IE8 renders in standards mode.

Set “X-UA-Compatible” (value: “IE=10;IE=9;IE=8”, or just “IE=Edge”) in your HTTP Headers, not in a META tag.

It turns out that IE8 sees the Modernizer comments in the html and throws itself into compatibility mode before it sees the tag, and once you’re in compatibility mode, the user has to override their own browser settings for your website to get themselves back into standards mode. However, if you send the “X-UA-Compatible” setting in the HTTP Headers, IE8 sees that first, and sticks in standards mode.

This is discussed briefly here at StackOverflow.