121

On microsoft's site they claim that simple doctype declaration is enough. But even a document as short as this falls back to IE7 mode:

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>

</body>
</html>

http://d.pr/i/fvzb+

5 Answers 5

245

Internet Explorer makes the assumption that most webpages were written to target earlier versions of IE and looks at the doctype, meta tags and HTML to determine the best compatibility mode (sometimes incorrectly). Even with a HTML5 doctype IE will still place your website in compatibility mode if it's an intranet site.

To ensure that your website always uses the latest standards mode you can either make sure Display intranet sites in Compatibly is turned off. However you have to do this on each machine local to the web server (instructions are below).

Alternatively, and better yet, you can use the X-UA-Compatible header to turn this off from the server. It's important to note that using the meta tag will not work!

<!-- Doesn't always work! -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Throughout MSDN it's mentioned that using a host header or a meta tag should override even intranet sites. The article Understanding compatibility modes in internet explorer 8 says the following.

A large number of internal business web sites are optimized for Internet Explorer 7 so this default exception preserves that compatibility. ... Again if a Meta tag or http header is used to set a compatibility mode to the document it will override these settings.

However, in practice this will not work, using a host header is the only option that works. The comments section of the article also shows numerous examples of this exact issue.

Using a Meta tag also has several other issues such as ignoring the tag if it's not directly under the <head> tag or if there is too much data before it (4k). It may also trigger the document to be reparsed in some versions of IE which will slow down rendering. You can read more about these issues at the MSDN article Best Practice: Get your HEAD in order.

Adding the X-UA-Compatible header

If you are using .NET and IIS you can add this to the web.config, you could also do this programmatically:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="X-UA-Compatible" value="IE=edge" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

If you're not using IIS it's easy to do in any language. For example, here's how to do it in PHP:

header('X-UA-Compatible: IE=edge');

As long as the X-UA-Compatible header is present with the HTML5 doctype, a site will always run in the latest standards mode.

Turning off Compatibility View
It may still be useful to turn off Compatibility View. To do so untick Display all intranet sites in compatibility view in the Compatibility View Settings.

Compatibility View Settings

You can bring this up by hitting Alt to get the menu.

enter image description here

Edit This answer also pertains to IE9.

18
  • Pardon my ignorance, but how to get to this Settings sheet? I checked Internet explorer settings, right-clicked the compatibility view in address bar - nothing.
    – firedev
    Nov 8, 2012 at 16:20
  • 2
    @Nick use alt to bring up the toolbar, it's under tools -> compat view settings Nov 8, 2012 at 23:16
  • Oh thank you, looks like that solved it. Makes one wonder why did they do that at all.
    – firedev
    Nov 9, 2012 at 5:00
  • 25
    +1000 ;). SO should force every OP to see this answer, when they are having any [IE] tag and a word "compatible" in their question, even before they actually post that question.
    – Teemu
    Nov 21, 2012 at 13:31
  • 2
    I tried adding the custom headers section to the project's web.config. It would appear that setting doesn't override the IE setting for using compatibility view for intranet sites. Aug 29, 2013 at 13:21
25

This works for me..

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
  • 11
    N.B. as Lavinski says above, "the meta tag doesn't do anything for intranet sites."
    – Nathan
    Jun 4, 2013 at 18:40
  • 2
    For what it's worth, for a hosted website (non-intranet site) that has the X-UA-Compatible meta tag, yet still isn't triggering IE10 Standards document mode as Page Default, I found that if the meta tag is located below script tags or is just too far from the top of the <head> in the DOM tree, IE10 cries and sets the document mode to IE8 Standards. So, keep your IE=edge meta tag close the <title> tag. Not always a simple a fix for Wordpress sites when it's not hard-coded in the header template file. Not sure if IE11 cares where the meta tag is, but hope this proves helpful to someone.
    – purefusion
    Oct 16, 2013 at 15:45
  • 1
    For blind copy and pasters such as myself, that is missing the closing tag. . <meta http-equiv="X-UA-Compatible" content="IE=edge"></meta> Jan 7, 2014 at 18:00
  • You only need to close the meta tag if you are using the XHTML doctype Jan 31, 2014 at 22:31
  • 2
    Also this tag needs to be the first tag inside <head> Feb 25, 2014 at 23:45
10

Try adding the following tag to the head

<meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8" />
8
  • 5
    That should be IE=Edge instead Nov 8, 2012 at 7:53
  • 1
    But there's a risk that future versions of IE does something bad and breaks your site Nov 8, 2012 at 9:05
  • 7
    No that's not a risk if you follow the spec, you don't see people doing that for chrome. Nov 8, 2012 at 10:14
  • 1
    This tag needs to be the first tag inside <head> Feb 25, 2014 at 23:45
  • 1
    The edit on this answer demonstrates why this is not a good idea. The accepted answer is the best solution.
    – Just a guy
    Mar 7, 2014 at 21:19
2

The meta tag doesn't do anything for intranet sites and my issue was IE10 rendering in IE10 compatibility mode. What tackled the issue for me was taking @Jeow's answer further and using that value in an http header by adding the following to web.config under IIS:

<system.webServer>
  <httpProtocol> 
    <customHeaders> 
      <clear />
      <!-- <add name="X-UA-Compatible" value="IE=edge" /> not good enough -->
      <add name="X-UA-Compatible" value="IE=11,IE=10,IE=9,IE=8" /> 
    </customHeaders> 
  </httpProtocol>
</system.webServer>

For IE purposes, intranet sites include public-facing sites that are not routed to externally - for example a Stackoverflow employee working from the office would probably see stackoverflow.com in compatibility mode.

1

It worked perfectly for me when i did the folowing:

On http://msdn.microsoft.com/en-us/library/gg699338(v=vs.85).aspx

Used the exact example they provide in the first box(added the missing </html> at the bottom), opened it in IE10 and standards was forced, i think you may need actual content in the html for it to force standards not sure though.

My suggestion would be to replace your empty code with actual content(something simple) and see what it does.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.