Internet Explorer 8/9 Document Modes
IE8 supports the following three document modes:
- Quirks mode (IE5 mode)
- Internet Explorer 7 standard mode
- Internet Explorer 8 standard mode
IE9 supports the following four document modes:
- Quirks mode (IE5 mode)
- Internet Explorer 7 standard mode
- Internet Explorer 8 standard mode
- Internet Explorer 9 standard mode
The Internet Explorer User-Agent String
IE8/9 has two different User-Agent strings. One when it runs in the Compatibility View and one when it runs not in the Compatibility View. When the IE is not running in the Compatibility View, the browser sends a string containing the "real" identity:
IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0) IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
But if it is running in the Compatibility View, the identity changes to IE7:
IE8: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0) IE9: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0)
The User-Agent string doesn't tell in which document mode (Quirks mode, IE7 standard mode, IE8 standard mode, etc.) the IE is running. This information can only be get from the property document.documentMode.
For more details have a look at: The Internet Explorer 8 User-Agent String
How-to run the different modes
There are two alternative ways to set the document mode for Internet Explorer 8/9:
- Use a certain meta tag in your HTML file
- Use a custom HTTP request header
Internet Explorer has some tags to run the document modes. The table below shows, which tag should be used to run the Internet Explorer in either of the modes:
| Tag | Mode | Description |
|---|---|---|
| IE=5 | Quirks | Runs IE in Quirks mode |
| IE=7 | IE7 standard | Runs IE in IE7 standard mode |
| IE=8 | IE8 standard | Runs IE in IE8 standard mode |
| IE=9 | IE9 standard | Runs IE in IE9 standard mode (works only with IE9) |
| IE=EmulateIE7 | Quirks or IE7 standard | Runs IE in Quirks mode if no <!DOCTYPE> is defined, otherwise it runs in IE7 standard mode |
| IE=Edge | best | Runs IE in the "best" available mode, IE8 in IE8 standard mode, IE9 in IE9 standard mode, and so on |
Use a certain meta tag in your HTML file
To select the document mode in an HTML file, you must set a certain <meta> tag. This <meta> tag must be the first tag in the <head> tag. The example below demonstrates how to run the document in IE7 standard mode.
<html> <head> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>My Web Page</title> </head> <body> <p>Content goes here.</p> </body> </html>
Note, if you set the content to "IE=EmulateIE7" then Internet Explorer 8/9 will switch to "Quirks mode", because the HTML file above has no <!DOCTYPE> defined.
The table above shows which tags can be used to run other document modes.
Use a custom HTTP request header
Another technique is to use a custom HTTP request header to set the document mode. The advantage is that you must not edit any HTML files to set the mode.
You have to add a "X-UA-Compatible" key, let's say with a value "IE=7" to run the IE7 standard mode.
An example to add a custom HTTP request header in Apache 2.2:
#Add header module LoadModule headers_module modules/mod_headers.so #Set header for all requests to IE7 standard mode Header set X-UA-Compatible: IE=7
The table above shows which tags can be used to run other document modes.
