Doctype switching

This document will summarize the different layout modes in popular web browsers and how they are triggered by common doctypes.

Pick browsers to display

Table of Contents

  1. Doctypes
  2. Differences from content types
  3. Doctype switching
  4. How to interpret this table
  5. Doctype switching rules
  6. Related sites

Doctypes

Up

A document type declaration (doctype) is a special identifier at the top of a webpage that contains or refers to a document type definition (DTD). A DTD tells the browser what elements and attributes exist in the document's markup language and where they may be used. A doctype is required at the top of every SGML and XML document, including HTML and XHTML. Webpages typically contain a doctype with a reference to a universally known DTD, rather than including all of the information in a custom-made file or the webpage itself. The danger of using a custom-made DTD is that while the web developer may understand what the custom elements and attributes mean, browsers and search engines don't.

Differences from content types

Up

A content type, also known as a mime type, tells the browser what kind of document it is, while a doctype only tells it what element and attribute names the user agent should expect to see. Many web developers mistakenly assume that giving a document an XHTML doctype makes the browser think it is an XHTML document. A document sent with the text/html content type and an XHTML doctype will still be treated as an HTML document, but with some “custom” differences in elements and attributes.

Doctype switching

Up

As web browsers started to follow web standards more rigidly, it was found that many websites relied on nonstandard browser behavior. It was also found that most of these websites didn't use doctypes or referenced to older DTDs. In order to maintain compatibility with these sites, browsers adopted the practice of doctype switching, also referred to as doctype sniffing. This is the practice of supporting multiple implementations of certain features, including one aimed to follow web standards and at least one to keep its old nonstandard behavior, and selecting the implementation based on certain aspects of the doctype. Websites without doctypes or with older doctypes are typically displayed using the old nonstandard models, while websites with full modern doctypes are typically displayed more in accordance with the standards.

Currently, most browsers support three modes for HTML documents: Standards mode, Almost Standards mode, and Quirks mode. Standards mode attempts to fully comply with the relevant web standards. Almost Standards mode is nearly identical to Standards mode except that img elements inside table cells are handled slightly differently in order to prevent gaps. Quirks mode has much more significant differences.

Although certain conditions may cause more than one browser to be in a certain layout mode, that does not mean those browsers will treat the page the same way. In particular, different browsers often have very different behavior when in quirks mode. The Web browser standards support resource details support for features aiming at standards mode, tested in each browser's closest mode to standards mode.

How to interpret this table

Up

Each row corresponds to a specific doctype, sometimes accompanied by other relevant markup. The layout mode for that markup is indicated by a single letter: S (standards mode), A (almost standards mode), or Q (quirks mode). An E means that the browser doesn't interpret the document as a webpage under the relevant conditions. A question mark (?) means that the layout mode for that doctype is currently unknown. The values have been colored for readability.

The table is split into several sections for the different document types. Unless otherwise indicated, the information for the HTML document types only applies to documents sent with the Content-type: text/html HTTP header, and the information for the XHTML document types only applies to documents sent with the Content-type: application/xhtml+xml HTTP header. XHTML 1.0 information is provided for both content types.

Be sure to read the doctype switching section for information about the different layout modes.

Doctype switching rules

Up
Doctype switching rules
Doctype IE 6 IE 7 Firefox 1.5 Opera 8.5 Opera 9
HTML 4.01 Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> Q Q Q Q Q
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> A A A A A
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> A A A A A
HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> A A S S S
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> A A S S S
XHTML 1.0 Transitional (text/html)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> A A A A A
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> A A A A A
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Q A A A A
XHTML 1.0 Strict (text/html)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> A A S S S
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> A A S S S
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Q A S S S
XHTML 1.0 Transitional (application/xhtml+xml)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> E E S S S
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> E E S S S
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
E E S S S
XHTML 1.0 Strict (application/xhtml+xml)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> E E S S S
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> E E S S S
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
E E S S S
XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> E E S S S
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
E E S S S