Forcing Internet Explorer 9 to use standards document mode

143,823

Solution 1

 <!doctype html>
 <meta http-equiv="X-UA-Compatible" content="IE=Edge">

This makes each version of IE use its standard mode, so IE 9 will use IE 9 standards mode. (If instead you wanted newer versions of IE to also specifically use IE 9 standards mode, you would replace Edge by 9. But it is difficult to see why you would want that.)

For explanations, see http://hsivonen.iki.fi/doctype/#ie8 (it looks rather messy, but that’s because IE is messy in its behaviors).

Solution 2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

The meta tag must be the first tag after the head tag or it will not work.

Solution 3

There is something very important about this thread that has been touched on but not fully explained. The HTML approach (adding a meta tag in the head) only works consistently on raw HTML or very basic server pages. My site is a very complex server-driven site with master pages, themeing and a lot of third party controls, etc. What I found was that some of these controls were programmatically adding their own tags to the final HTML which were being pushed to the browser at the beginning of the head tag. This effectively rendered the HTML meta tags useless.

Well, if you can't beat them, join them. The only solution that worked for me is to do exactly the same thing in the pre-render event of my master pages as such:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    Dim MetaTag As HtmlMeta = New HtmlMeta()
    MetaTag.Attributes("http-equiv") = "Content-Type"
    MetaTag.Attributes("content") = "text/html; charset=utf-8;"
    Page.Header.Controls.AddAt(0, MetaTag)

    MetaTag = New HtmlMeta()
    MetaTag.Attributes("http-equiv") = "X-UA-Compatible"
    MetaTag.Attributes("content") = "IE=9,chrome=1"
    Page.Header.Controls.AddAt(0, MetaTag)
End Sub

This is VB.NET but the same approach would work for any server-side technology. As long as you make sure it's the last thing that gets done right before the page is rendered.

Solution 4

To prevent quirks mode, define a 'doctype' like :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

To make IE render the page in IE9 document mode :

<meta http-equiv="x-ua-compatible" content="IE=9">

Please note that "IE=edge" will make IE render the page with the most recent document mode, rather than IE9 document mode.

Solution 5

put a doctype as the first line of your html document

<!DOCTYPE html>

you can find detailed explanation about internet explorer document compatibility here: Defining Document Compatibility

Share:
143,823
MaxRecursion
Author by

MaxRecursion

Student/IT Professional/ Windows Phone Enthusiast/ Micro-Blogger/ Internet freak/ Computer fanatic /StackExchange Fan/ Android Developer http://MaxRecursion.wordpress.com/ http://twitter.com/MaxRecursion

Updated on May 23, 2020

Comments

  • MaxRecursion
    MaxRecursion almost 4 years

    How can I force Internet Explorer 9 to use standards document mode? I built a website and I'm finding that IE9 uses quirks mode to render the website pages. But I want to use standards mode for rendering.

  • leoinlios
    leoinlios about 11 years
    @ inancsevinc: My aspx page already had <!DOCTYPE html> and it was still using IE7 document mode when rendered. So in this sense your suggestion alone did NOT resolve my problem. The trick for me was to add <meta http-equiv="X-UA-Compatible" content="IE=Edge"> immediately below it as suggested by Jukka K. Korpela. I do appreciate that your sugegstion may be valid, I just don't understand why it alone would not force IE to IE9 mode for me.
  • teewuane
    teewuane about 11 years
    This doesn't work if your content is loading into an iframe and the parent window doesn't have a doctype specified. It will follow apply the quirks mode to the iframe as well. I hate microsoft. Also here is a link to a microsoft site talking about this answer. msdn.microsoft.com/en-us/library/ie/hh920756(v=vs.85).aspx
  • crush
    crush over 10 years
    It also doesn't work if you have content besides the DOCTYPE declaration before the HTML tag.
  • DrCord
    DrCord over 10 years
    This answer was correct awhile ago, but now that IE10 is out this will render in that and in the future will render whatever the newest IE is. See SuperDuck's answer below to render in IE9 explicitly.
  • 15ee8f99-57ff-4f92-890c-b56153
    15ee8f99-57ff-4f92-890c-b56153 over 10 years
    This has no effect on my 64-bit copy of IE9 (version 9.0.8112.16421). ("HTML1115: X-UA-Compatible META tag ('IE=8') ignored because document mode is already finalized.", regardless of where the meta tag is located in the document)
  • 15ee8f99-57ff-4f92-890c-b56153
    15ee8f99-57ff-4f92-890c-b56153 over 10 years
    ...must call Response.AddHeader() (stuck w/ classic ASP in this case) or whatever equivalent. Who knows what'll happen with IE10, IE9 on anybody's desktop but mine, or anything else...
  • Dan Rayson
    Dan Rayson about 9 years
    I had the same issue, I use DNN in my site (ewwww) and this was the only solution to the problem, all the other assumed you had direct control over the <head> tag in HTML.
  • JensG
    JensG over 8 years
    I always wonder what happens when at some day another meta tag is needed that also must be placed before all others ...
  • Mikko Rantalainen
    Mikko Rantalainen over 5 years
    You really want to put meta charset as close to the start of the document as possible. I guess both can still fit in small enough count of bytes to work with real world user agents.