253

I am quite confused. I should be able to set

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

and IE8 and IE9 should render the page using the latest rendering engine. However, I just tested it, and if Compatibility Mode is turned on elsewhere on our site, it will stay on for our page, even though we should be forcing it not to.

How are you supposed to make sure IE does not use Compatibility Mode (even in an intranet)?

FWIW, I am using the HTML5 DocType declaration (<!doctype html>).

Here are the first few lines of the page:

<!doctype html> 
<!--[if lt IE 7 ]> <html lang="en" class="innerpage no-js ie6"> <![endif]--> 
<!--[if IE 7 ]>    <html lang="en" class="innerpage no-js ie7"> <![endif]--> 
<!--[if IE 8 ]>    <html lang="en" class="innerpage no-js ie8"> <![endif]--> 
<!--[if (gte IE 9)|!(IE)]><!--> 
<html lang="en" class="innerpage no-js"> 
<!--<![endif]--> 
    <head> 
        <meta charset="ISO-8859-1" /> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

EDIT: I just learned that the default setting on IE8 is to use IE7 compatibility mode for intranet sites. Would this override the X-UA-Compatible meta tag?

Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
Kerrick
  • 7,420
  • 8
  • 40
  • 45
  • I'm having this problem too with some of my users, did you ever figure this out? My app isn't intranet though. And only like 20% of the users get it, strangely. – Kevin Jun 29 '11 at 22:20
  • 2
    This might be the result of your funny tag markup (the – Sunday Ironfoot May 21 '12 at 09:45
  • 13
    @SundayIronfoot FYI, the funny tag markup you refer to is conditional IE comments that is used to add a CSS class to the element for the appropriate version of IE (if applicable) so you can style things differently as needed for the IE versions by simply prefixing your style declaration with ".ie7 ", like: .ie7 p { width: 200px; } ... it's a cleaner work around for rendering issues in older IE versions than having to use some of the CSS hacks like *width or _width. Browsers other than IE will ignore it and just use the basic one. – Tim Franklin Jan 18 '13 at 17:12

18 Answers18

263

If you need to override IE's Compatibility View Settings for intranet sites you can do so in the web.config (IIS7) or through the custom HTTP headers in the web site's properties (IIS6) and set X-UA-Compatible there. The meta tag doesn't override IE's intranet setting in Compatibility View Settings, but if you set it at the hosting server it will override the compatibility.

Example for web.config in IIS7:

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

Edit: I removed the clear code from just before the add; it was an unnecessary oversight from copying and pasting. Good catch, commenters!

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Tim Franklin
  • 3,060
  • 2
  • 16
  • 15
  • 5
    Just a note though... If you're developing using the built-in Visual Studio development web server (a.k.a. Cassini), then this won't work because Cassini doesn't honor the section of the web.config. So, for development, use IIS Express instead. – James Messinger Jul 16 '12 at 17:54
  • 1
    What's the reason for the ``? What custom headers are cleared by this? – M4N Dec 07 '12 at 09:48
  • The clear seems to remove the `` rule at least for me. That rule does gzipping, which I do want so I commented out the clear. Any further information would be lovely. – Joel Peltonen Dec 07 '12 at 13:10
  • I removed the 'clear' - good catch, it was an unnecessary line from copying and pasting from my implementation. – Tim Franklin Dec 14 '12 at 04:46
  • 14
    PHP: `` – Nux Apr 11 '13 at 14:21
  • @Nux Need your help! Could you tell me where to add it? I am using PHP. Should I add it before or after . Thanks! – sunskin Apr 23 '14 at 15:56
  • Headers need to be set before any HTML is sent to the browser. So before doctype. – Nux Apr 24 '14 at 16:45
  • We have apache servers, what do I need to do? – Jared Christensen May 05 '14 at 14:41
  • rather than using `` should you do `` prior to the add? – kenwarner Jul 11 '14 at 16:17
  • Dennis Ritchie bless you! – adripanico Sep 19 '14 at 07:09
  • clear is needed in other cases where an add might cause an error if the same item is added in a parent config. –  Dec 02 '16 at 13:24
  • Just as a note: in Java and Tomcat I had to implement a filter and map it to Faces Servlet. On this filter, at he begining of the `doFilter` method I added: `response.addHeader("X-UA-Compatible", "IE=edge");` – Oscar Pérez Apr 11 '18 at 08:41
185

Server Side solution is the recommended one, as @TimmyFranks proposed in his answer, but if one needs to implement the X-UA-Compatible rule on the page level, please read the following tips, to benefit from the experience of the one who already got burned


The X-UA-Compatible meta tag must appear straight after the title in the <head> element. No other meta tags, css links and js scripts calls can be placed before it.

<head>
    <title>Site Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <script type="text/javascript" src="/jsFile.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
    <link rel="shortcut icon" href="/apple-touch-icon.png" />
</head>

If there are any conditional comments in the page (lets say located in the <html>), they must be placed under, after the <head>.

// DON'T: place class inside the HTML tag 
<!--[if gt IE 8]><!--> 
    <html class="aboveIe8"> 
<!--<![endif]-->

// DO: place the class inside the BODY tag
<!--[if gt IE 8]><!--> 
    <body class="aboveIe8"> 
<!--<![endif]-->

Html5BoilerPlate's team wrote about this bug - http://h5bp.com/i/378 They have several solutions.

Regarding Intranet & Compatibility view, there're settings when you go to tools > Compatibility view settings.

Compatibility view settings

Community
  • 1
  • 1
neoswf
  • 4,730
  • 6
  • 39
  • 59
  • 1
    I have tried 4 or 5 other answers on Stack Overflow, and only this specific combination worked for me. For anyone using WordPress and an SEO plugin, be careful about the plugin rewriting the in another location. Edit: Added WordPress comment – Mike Ebert Jul 17 '13 at 18:26
  • 6
    `X-UA-Compatible` should appear as early as possible, [probably after `charset`](https://github.com/h5bp/html5-boilerplate/blob/master/index.html). I don't think it's true that it "must appear straight after the title". – sam Aug 29 '13 at 19:32
  • This recommendation is a result of suffering under IE. Been gained by blood. Who says IE following guidelines? – neoswf Sep 02 '13 at 20:46
  • 4
    Wow, this worked for me and having my meta tags right after the title tag is what did the trick. Wish it weren't so archaic to make this work... – theJerm Jul 22 '14 at 16:37
  • The `X-UA-Compatible` meta tag can appear after `title`, `base` and any other meta tags without losing its effect. This is what I tested in IE8. No conditional comments can be put before it, though. – Rockallite Mar 14 '16 at 05:16
  • oh my god, internet explorer 10 still suffers from this... it's thanks to your post I figured out whats wrong... – Tschallacka May 02 '16 at 08:25
  • Placing the **conditional comments** after the `` tag works for me along with the meta tags! Thanks @neoswf – Sheikh M. Haris May 10 '16 at 05:35
  • 1
    Did not work on IE11 with: – Taranjit Kang Dec 05 '17 at 14:57
37

Note that if you are serving it from PHP, you can use the following code to fix it as well.

header("X-UA-Compatible: IE=Edge");
TJ L
  • 23,914
  • 7
  • 59
  • 77
  • 4
    This works better than adding the meta tag, since it passes W3C validation using this method and is much easier than an .htaccess hack. – Talvi Watia Sep 18 '12 at 17:28
  • 2
    I tried everything else, and this was what finally worked. Thank you. – Jason Dec 13 '12 at 16:12
  • 2
    For those on WordPress, this may help: http://codex.wordpress.org/Plugin_API/Action_Reference/send_headers – ambiguousmouse Feb 04 '13 at 05:19
  • This works a lot better also when a huge site is built depending on `` – OZZIE Jan 16 '14 at 14:56
  • For anyone using PHP and coming here from google, THIS IS THE CORRECT ANSWER because it's the best solution out there! Send the headers before any content! – degenerate Feb 27 '14 at 19:05
  • Should this - header("X-UA-Compatible: IE=Edge"); be added straight after the title in the element? – sunskin Apr 24 '14 at 17:51
  • 2
    @sunskin - Any header's sent by PHP *MUST* happen prior to sending any output to the page, that is before any HTML or data is output by PHP. – TJ L Apr 25 '14 at 13:55
26

As it turns out, this has to do with Microsoft's "intelligent" choice to make all intranet sites force to compatibility mode, even if X-UA-Compatible is set to IE=edge.

Kerrick
  • 7,420
  • 8
  • 40
  • 45
  • 32
    That's not true. The X-UA-Compatible will override the compatibility mode setting. However, sometimes using the meta tag does not work because the mode has already been set by the time it encounters it. This is why I use the HTML header version, so the browser can enable standards mode early in the process. – Erik Funkenbusch Jun 26 '12 at 18:12
  • 3
    Adding to Mystere Man's comment, you can override it from the hosting server using the web.config or the custom http headers in IIS. See my post above for details. – Tim Franklin Aug 09 '12 at 18:38
  • 7
    I have tried this multiple times and it does not override all intranet sites forced to comparability mode. – Maess May 09 '13 at 13:23
  • @Mystere Man: Define sometimes as whenever the page is in an iframe, where the parent document doesn't define XUA-COMPAT, and the document mode is inherited from the parent page (another very intelligent MS choice). – Stefan Steiger Jul 03 '13 at 12:15
  • 1
    @Kerrick: This is not the correct answer. See the one below this answered by tj111 for the correct answer. – degenerate Oct 29 '13 at 18:19
  • When the user has turned on Compatibility View you cannot override it from the server or html page. This value is saved in the Windows registry and cannot be accessed via a page. If you think about it it would be dangerous to manipulate an app from a web site. – mbokil Jan 12 '14 at 02:24
  • @ErikFunkenbusch I can assure you that the X-UA-Compatibility flag does not override a group policy compatibility mode. – Andrew T Finnell Jul 05 '18 at 12:34
9

I also got the same issue of IE9 rendering in IE7 Document standards for local host. I tried many conditional comments tags but unsuccesful. In the end I just removed all conditional tags and just added meta tag immediatly after head like below and it worked like charm.

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Hope it helps

Pramod
  • 91
  • 1
  • 1
8

Even if you have unchecked the "Display intranet sites in Compatibility View" option, and have the X-UA-Compatible in your response headers, there is another reason why your browser might default to "Compatibility View" anyways - your Group Policy. Look at your console for the following message:

HTML1203: xxx.xxx has been configured to run in Compatibility View through Group Policy.

Where xxx.xxx is the domain for your site (i.e. test.com). If you see this then the group policy for your domain is set so that any site ending in test.com will automatically render in Compatibility mode regardless of doctype, headers, etc.

For more information, please see the following link (explains the html codes): http://msdn.microsoft.com/en-us/library/ie/hh180764(v=vs.85).aspx

rshadman
  • 405
  • 5
  • 8
5

As NEOSWF points out above, the Paul Irish conditional comments stops the meta tag having any affect.

There are several fixes all here (http://nicolasgallagher.com/better-conditional-classnames-for-hack-free-css/)

These include:

Adding two HTML classes, using server headers and adding a conditional comment above the doctype.

On my latest project I decided to remove the Paul Irish conditional comments. I didn't like the idea of adding anything before the html without doing LOTS of testing first and it's nice to see what has been set just by looking at the HTML.

In the end I surrounded a div straight after the body and used conditional comments eg

  <!--[if IE 7]><div class="ie7"><!--<![endif]-->
  ... regular body stuff
  <!--[if IE 7]></div><!--<![endif]-->

I could have done this around the body but its more difficult with CMSs like Wordpress.

Obviously its another DIV inside the markup, but its only for older browsers.

I think it could be a per project based decision though.

I've also read something about the charset meta tag needing to come in the first 1024 bytes so this ensures that.

Sometimes the simplest, easiest to read ideas are the best and its definitely worth thinking about! Thanks to the 6th comment on the link above for pointing this out.

T. Junghans
  • 11,385
  • 7
  • 52
  • 75
user1010892
  • 1,179
  • 3
  • 14
  • 25
5

X-UA-Compatible will only override the Document Mode, not the Browser Mode, and will not work for all intranet sites; if this is your case, the best solution is to disable "Display intranet sites in Compatibility View" and set a group policy setting to specify which intranet sites need compatibility mode.

andyg0808
  • 1,367
  • 8
  • 18
Tony
  • 364
  • 4
  • 3
5

I added the following to my htaccess file, which did the trick:

BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
Metzed
  • 470
  • 1
  • 8
  • 27
  • 1
    this works when intranet is set to compatibility. took me long time to find something that will work. specially when you search and everything is iis related – shorif2000 Sep 18 '13 at 14:30
  • This is awesome. I didn't know you could send headers with .htaccess – Alex W Nov 25 '13 at 15:56
3

Additionally, X-UA-Compatible must be the first meta tag in the head section

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>

By the way, the correct order or the main head tags are:

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <title>Site Title</title>
    <!-- other tags -->
</head>

This way

  1. we set the render engine to use before IExplorer begins to process
  2. the document then we set the encoding to use for all browser
  3. then we print the title, which will be processed with the already defined encoding.
  • 2
    Actually, the CHARSET should precede the X-UA-Compatible. See http://blogs.msdn.com/b/ieinternals/archive/2011/07/18/optimal-html-head-ordering-to-avoid-parser-restarts-redownloads-and-improve-performance.aspx – EricLaw Apr 22 '14 at 15:14
  • 1
    It doesn't have to be first, but it does need to be near the top. It can follow title (and charset, as Eric noted), but that's about it. – Lance Leonard Nov 04 '14 at 18:52
  • in my case on nginx it will only work if the X-UA-Compatible-tag is the first in the head section – Marco Roth Jan 11 '17 at 07:46
2

For Nginx,

add_header "X-UA-Compatible" "IE=Edge,chrome=1";

ref : https://github.com/h5bp/server-configs/commit/a5b0a8f736d68f7de27cdcb202e32975a74bd2c5

z2z
  • 519
  • 1
  • 8
  • 16
2

Timmy Franks had it right for me. We just had the issue today where the client had IE8 company-wide, and it was forcing the site we wrote for their intranet into compatibility mode. Setting "IE-Edge" seemed to fix it.

<httpProtocol>
  <customHeaders>
    <clear />
    <add name="X-UA-Compatible" value="IE=Edge" />
  </customHeaders>
</httpProtocol>
SouthShoreAK
  • 4,176
  • 2
  • 26
  • 48
1

IE 11 doesn't allow you to override the browser compatibility view setting anymore by sending the header...

<meta http-equiv="X-UA-Compatible" content="IE=edge" />  

It appears the only way to force the browser to not use compatibility view is to have the user disable it in their browser. Ours is an Intranet site, and the default IE option is to use compatibility view for Intranet sites. What a pain!

We were able to prevent the need for the user to change their browser settings for users of IE 9 and 10, but it no longer works in IE 11. Our IE users are switching to Chrome, where this is not a problem, and never has been.

EricP
  • 147
  • 1
  • 4
  • It's not that it doesn't allow it, `IE11` doesn't support other Compatibility Modes other than `edge`. [Link to official documentation](http://msdn.microsoft.com/en-us/library/jj676915%28v=vs.85%29.aspx). That means we don't have to use that meta tag to hide the CM button on the address bar anymore. – Wallace Sidhrée Jan 22 '14 at 15:07
  • 4
    Untrue: IE11 still supports all legacy Compatibility Modes. – EricLaw Feb 03 '14 at 21:43
  • @EricLaw, is EricP's answer correct (that IE11 changes the behavior for the X-UA-Compatible HTTP header)? – Matthew Flaschen Apr 21 '14 at 22:52
  • @EricP, did you try the HTTP header, or only the tag version? – Matthew Flaschen Apr 21 '14 at 23:01
  • 2
    @MatthewFlaschen: No, EricP is incorrect, as is Wallace Sidhree (although to be fair to Wallace, MSDN doesn't explain what they mean by "deprecated"). What changed in IE11 is that there's no visible "Compatibility View" button at all (http://technet.microsoft.com/en-us/library/dn321449.aspx) but the X-UA-Compatible declarations are still respected. – EricLaw Apr 22 '14 at 15:13
  • In the MSDN documentation, "deprecated" means the feature is still available in the binaries, but there's no guarantee it won't be pulled soon. You're strongly encouraged to update things to alternate solutions. "Obsolete" means the feature is no longer supported by the binaries and you must update things to use alternate techniques. As an example: conditional comments were deprecated as of IE10. As of IE11, they're obsolete. Also, starting with IE11, legacy document modes and supported only for IE on the desktop. The, er, "Windows store experience" of IE supports only edge mode. – Lance Leonard Nov 04 '14 at 18:49
  • I tried on IE11 as well, with the meta below and it did not work. Also with other IE versions etc. – Taranjit Kang Dec 05 '17 at 14:56
1

I was able to get around this loading the headers before the HTML with php, and it worked very well.

<?php 
header( 'X-UA-Compatible: IE=edge,chrome=1' );
header( 'content: width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' );
include('ix.html');
?> 

ix.html is the content I wanted to load after sending the headers.

1

I was experiencing the same issue in IE11. None of these answers solved my issue. After digging a bit, I noticed that the browser was running in Enterprise mode. (verify by hitting F12 and click the emulation tab, look for browser profile dropdown) The setting was locked, not allowing me to change the setting.

I was able to change the profile to Desktop after deleting CurrentVersion from the following registry key:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode

After changing the mode to Desktop the answers on this post will work.

jfatal
  • 245
  • 1
  • 3
1

When your browser opens with Compatibility Modes, even you remove and turn off all compability modes configuration from your web browser and Local Group Policy Editor, you can try to disable from register key.

This also happen to me on using domain and sub-domain to connect server side. The machine is restricted to open in compability mode for all sub-domain.

DISABLE COMPABILITY MODE FOR INTRANET

HKEY_LOCAL_MACHINE - SOFTWARE - Policies - Microsoft - Internet Explorer - BrowserEmulation -> IntranetCompalityMode Value should be 0 (zero). And also remove existing domain name from PolicyList.

Otherwise, you can add a new value (DWORD) that contain 0 (zero) value data.

ayciceksamet
  • 73
  • 10
0

I had the same issue after trying many combination I had this working note I have compatibility checked for intranet

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<head runat="server">
capadleman
  • 85
  • 6
0

If you are using LAMP stack, then add this into your .htaccess file in your web root folder. No need to add it to every PHP file.

<IfModule mod_headers.c>
    Header add X-UA-Compatible "IE=Edge"
</IfModule>