74

I am coding a Frontend which works well in IE7 Standards Mode and IE8 Standards Mode.

When I start up Internet Explorer and load the page both IE7 and IE8 go to Quirks Mode directly. How can I force both IE7 and IE8 to always load the page in Standards Mode?

I have no special meta tags added so far.

Thanks for helping me out

Edit: My doctype and head looks as follows at the moment:

<!DOCTYPE html> 
<html lang="de"> 
<head> 
    <title>...</title> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8" />
    <script src="js/html5.js"></script> 

    (...)
</head>
4
  • 7
    I know I'm late to the party, but here's a quick note: if you set the render mode in the IE developer tools, that mode will stick next time you load the page. So, if you choose Quirks Mode, it'll stick with that mode until you change it manually or close the tab. So, enjoy.
    – Matchu
    Aug 27, 2011 at 20:00
  • 1
    Matchu, your comment was invaluable to me. By manually setting the render mode I was completely messing up my testing! Thank you! :) Feb 21, 2013 at 15:11
  • Unless you use a http header it won't always work stackoverflow.com/a/17258683/200442 Jun 23, 2013 at 7:49
  • 1
    It's really simple: Determining IE 9’s Document Mode
    – sam
    Sep 9, 2013 at 21:00

6 Answers 6

87

This is the way to be absolutely certain :

<!doctype html> <!-- html5 -->
<html lang="en"> <!-- lang="xx" is allowed, but NO xmlns="http://www.w3.org/1999/xhtml", lang:xml="", and so on -->
<head>
<meta http-equiv="x-ua-compatible" content="IE=Edge"/> 
<!-- as the **very** first line just after head-->
..
</head>

Reason :
Whenever IE meets anything that conflicts, it turns back to "IE 7 standards mode", ignoring the x-ua-compatible.

(I know this is an answer to a very old question, but I have struggled with this myself, and above scheme is the correct answer. It works all the way, everytime)

11
  • @Sameer Alibhai, off course! It is so implied that I forgot it ;-) now corrected . Jan 23, 2013 at 9:34
  • 1
    This is unfortunately not correct, a web server on the local network will still enable quirks mode when you have all this stuff. It's also IE=edge, not just Edge in the content of the meta tag.
    – mjaggard
    Feb 1, 2013 at 9:21
  • 3
    @davidkonrad: so where does lang info and ie-specific classes go then? My html at the moment looks like this (example IE8): <html class="ie ie8 ie_old" lang="it-IT"> Sorry, cannot comment to last answer, don't have the necessary reputation yet...
    – blu bla
    Feb 1, 2013 at 16:21
  • 1
    @davidkonrad You are allowed to have a lang attribute on your html tag, and also have a compatible meta tag! May 21, 2013 at 13:12
  • 1
    Had a problem just today with a Website being completely destroyed in IE9 for no obvious reasons. Removing all attributes from the html tag did the trick! Thank you a thousand times, was stuck for almost 2 hours already trying everything I could imaging!
    – Kevin G.
    Jul 13, 2015 at 13:10
34

Sadly, they want us to use a tag to let their browser know what to do. Look at this documentation, it tell us to use:

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

and it should do.

4
  • 3
    This won't kick it out of quirks-mode or into quirks-mode but will only change the "emulation mode". IE6 can run in non-quirks mode (although that doesn't mean it isn't very quirky!).
    – user166390
    Mar 21, 2011 at 5:29
  • If should force the thing to load in standards mode.
    – Alfabravo
    Mar 21, 2011 at 5:33
  • This works for IE8. However, IE7 still goes to quirks mode first.
    – maze
    Mar 21, 2011 at 5:35
  • IE7 is a real pain. Good to know that behavior you tell us, maze.
    – Alfabravo
    Mar 21, 2011 at 5:36
11
  1. Using html5 doctype at the beginning of the page.

    <!DOCTYPE html>

  2. Force IE to use the latest render mode

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

  3. If your target browser is ie8, then check your compatible settings in IE8

I blog this in details

10

Adding the correct doctype declaration and avoiding the XML prolog should be enough to avoid quirks mode.

3
  • This is the right way to achieve the thing, must say. Somehow, one don't know with IE...
    – Alfabravo
    Mar 21, 2011 at 5:34
  • 1
    This doesn't work with IE if you're running your web server on the local network :-(
    – mjaggard
    Feb 1, 2013 at 9:19
  • This link to wikipedia quirks mode, saved my day. I was struggling with it last 2 days and really didn't know what is happening with me in IE. But I wonder that when I used to enforce my IE to Standard Mode it appears as Document Mode: IE7 standards. How can I enforce it to IE9 Standard
    – Nah
    Jul 24, 2017 at 11:16
9

I know this question was asked over 2 years ago but no one has mentioned this yet.

The best method is to use a http header

Adding the meta tag to the head doesn't always work because IE might have determined the mode before it's read. The best way to make sure IE always uses standards mode is to use a custom http header.

Header:

name: X-UA-Compatible  
value: IE=edge

For example in a .NET application you could put this in the web.config file.

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>
2
  • 1
    Not the best one, since MS states that "If both [meta and header] of these instructions are sent, the developer's preference (meta element) takes precedence over the web server setting (HTTP header)." msdn.microsoft.com/en-us/library/ff955275%28v=vs.85%29.aspx
    – psychowood
    Apr 11, 2014 at 16:32
  • 1
    However you have to be careful because IE can decide the X-UA-Compatible value before reaching your Meta tag. That's why the header is still the best approach. Apr 17, 2014 at 5:34
2

It's possible that the HTML5 Doctype is causing you problems with those older browsers. It could also be down to something funky related to the HTML5 shiv.

You could try switching to one of the XHTML doctypes and changing your markup accordingly, at least temporarily. This might allow you to narrow the problem down.

Is your design breaking when those IEs switch to quirks mode? If it's your CSS causing things to display strangely, it might be worth working on the CSS so the site looks the same even when the browsers switch modes.

1
  • The HTML5 doctype was designed to put all browsers into standards mode.
    – mjaggard
    Feb 1, 2013 at 9:20

Your Answer

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

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