Resources > DOCTYPEs

This gives information about DOCTYPEs.

Introduction 

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 Strict standard is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.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.

List of DOCTYPEs 

Here are the DOCTYPEs listed in the various W3C specs:

How DOCTYPES Affect Rendering 

DOCTYPEs affect how pages are rendered in Gecko-based browsers, IE5//Mac, IE6 and IE7, IE8, Opera, and Safari.

Gecko-Based Browsers

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.

IE 5 // Mac

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…]

IE 6-7

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.

IE 8

For IE 8 the situation is more complex:

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.

Opera 7-9

The rendering modes depend on the version of Opera. For details, see Henri Sivonen’s DOCTYPE page (the section titled Doctype Sniffing).

Safari

This has the same rendering modes as the Gecko-based browsers.

Recommended DOCTYPEs 

I recommend that designers code to the standards as much as possible, normally using one of these DOCTYPEs:

I also recommend that designers use the IE8 metatag which tells IE8 to apply the standards strictly, using one of these metatags:

Note : IE6 has a bug which requires that an xHTML DOCTYPE appear on the first line of the HTML file for standards mode to be triggered.

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.

 Top of Page   Legal Notices