Document Types

The document type (doctype) tells which version of X/HTML your document is. It also tells the browser whether it should render in Standards Compliance Mode, Almost Standards Mode, or Quirks Mode. Standards Compliance Mode is best. In Standards Compliance Mode, browsers render pages as close to the standards as they can, which of course is much closer in some browsers than in other browsers. Some of the articles listed below describe which doctypes trigger which modes in various browsers, so I'm not going to go into detail here. What I'll say is that you should use a complete doctype (one that includes a URL) and that Strict doctypes are best.

I recommend HTML 4.01 Strict and usually use it myself. A doctype is not a magic fix. It is the first step in the process of making your page display the same or very close to the same in a variety of web browsers.

Which doctype you use will influence which box model is used in some browsers, including IE6 and IE7. Also there is a bug in IE6 where if you put anything before the doctype, including an XML Declaration, it will cause IE6 to render in Quirks Mode (aka backwards compatibility mode), which includes using the IE5.x/Win box model. The XML Declaration won't cause IE7 to go into Quirks mode, but putting a comment before the doctype will.

Strict Doctypes are Best

Strict Doctypes require you to remove presentation markup, iframes, and the target attribute that are allowed by Transitional doctypes. You can read reasons why its best to avoid using iframes here. The functionality of the target attribute can be handled with JavaScript. When you're not using frames and iframes you only would use the target attribute to force links to open in new windows anyway, which is often best left for the user to choose.

Doctypes

HTML 4.01 Strict

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

HTML 4.01 Transitional

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

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

Other Articles on Choosing Your Document Type