This gives information about DOCTYPEs.
A DOCTYPE line should appear at the beginning of an HTML or xHTML file to specify the standard applicable to the file. E.g., the DOCTYPE for the HTML 4.01 Transitional standard is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
There are two reasons for specifying a DOCTYPE:
Note : the role of the DOCTYPE in HTML 5 is not clear. The draft specification says that it is required but essentially useless, however, it seems likely that validators, browsers, and other user agents will use it to determine which specification to apply.
The rest of this page presents a list of the doctypes and a discussion of how DOCTYPEs affect rendering.
Here are the DOCTYPEs listed in the various W3C specs:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">DOCTYPEs affect how pages are rendered in Gecko-based browsers, IE5//Mac, IE6 and IE7, IE8, Opera, and Safari.
These browsers have three modes of rendering pages:
How the mode is chosen is different from IE, and more complex. For details, see the information from Mozilla.
This browser has two modes of rendering pages:
Bugwards Compatibility Mode will be chosen if the DOCTYPE is missing, or if it is a Transitional or Frameset DOCTYPE with no URL. Otherwise Standards Mode will be chosen. [details...]
For IE 6 and 7, there are two modes of rendering pages:
How the mode is chosen is a bit different from IE5//Mac, and a bit more complex. For details, see Microsoft’s DOCTYPE page.
Note: IE7 supports standards better with a strict DOCTYPE.
For IE 8 the situation is more complex, because there are three different ways to specify the mode of rendering pages:
As is true of other browsers, the designer may put a DOCTYPE in the page to specify the mode. In this case there are two modes of rendering pages:
The designer may put a meta tag in the page to tell IE8 to emulate an older version of IE. In this case there are four modes of rendering pages:
Microsoft expects designers to insert the meta tags in current sites until the sites have been updated to make them IE8-compatible.
All this is discussed in Microsoft’s Defining Document Compatibility.
These details are subject to change, as Microsoft may change its mind, as it has done several times already.
The rendering modes depend on the version of Opera. For details, see Henri Sivonen’s DOCTYPE page (the section titled Doctype Sniffing).
This has the same rendering modes as the Gecko-based browsers.
I recommend that designers code to the standards as much as possible, normally using one of these DOCTYPEs:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Note : IE6 has a bug which requires that the xHTML DOCTYPE appear on the first line of the HTML file for standards mode to be triggered.
For sites that attract users with extremely old browsers — e.g. NN3 and very early versions of NN4 — I recommend this instead, which allows HTML tags that are deprecated with the above DOCTYPEs:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">All three of the above DOCTYPEs trigger standard mode in modern browsers, but the first can trigger the strongest compliance with standards.
An HTML DOCTYPE is theoretically better than an xHTML DOCTYPE, because many browsers do not specifically support xHTML. I myself use an xHTML DOCTYPE, however, because real-world browsers that do not support xHTML will render pages fine, just as if they were HTML.
Most of my older sites are xHTML Transitional; newer sites are Strict.