A Document Type Declaration should generally appear at the top of an HTML document to let the browser know which version of HTML to expect. Here's an example for XHTML documents:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">For regular HTML (we could be using XHTML by now, but browsers aren't perfect) use the following info - DaveEveritt:
The most reasonable DOCTYPE to use is HTML 4.01 Transitional (approved by W3C as a minor revision to the earlier 4.0):
<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html40/loose.dtd">In both IE and NN the lack of a doctype declaration, the use of a pre-HTML 4.0 doctype declaration or the use of an HTML 4.x Transitional doctype declaration without an URI trigger the respective quirks modes.
HTML 4.x Strict doctype declarations, XHTML 1.0 doctype declarations and the HTML 4.01 Transitional doctype declaration with the URI trigger the respective standards modes in both browsers. However, the HTML 4.0 Transitional doctype declaration with the URI triggers the quirks mode in Mozilla and the standards mode in IE 5 for Mac.
HTML 4.01 Transitional doctype declaration with the URI ie.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">- Standards
HTML 4.0 Transitional doctype declaration with the URI ie.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">- Quirks in Mozilla, Standards in IE 5 for Mac
DTDs for framesets:
<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html40/frameset.dtd">- Individual frames should use a regular DOCTYPE such as HTML 4.01 Transitional.
...so which HTML DTD to use?
Document contains TagSoup? and/or relies on quirks. (Authoring new pages like this is a bad thing.):
No doctype declarationNOTE A doctype declaration should not be included in a document that doesn't validate or relies on the old layout model of Navigator 1.x through 4.x.
Document validates as HTML 4.01 Transitional (may contain deprecated markup) and works with the CSS2 box layout model:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">Document validates as HTML 4.01 Strict and works with the CSS2 box layout model:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">NOTE Compatibility with the CSS2 box layout model is important. In particular, the vertical alignment of images and the vertical sizing of boxes around images is noteworthy. Mozilla honors the CSS2 specification when calculating the height of boxes in its standards layout mode. IE 5 for Mac uses the Navigator 1.x model with boxes around images even in its standards mode. Testing image alignment in IE 5 for Mac alone is inadequate. Mozilla M18 or Netscape 6 PR3 are't suitable, either. Newer builds are.
XHTML:
With XHTML, you are also supposed to use an XML declaration at the very top of the document (above the DOCTYPE):
<?xml version="1.0" encoding="UTF-8"?>NOTE: unfortunately, this seems to mess up some versions of MSIE for the Mac, making them display the document as plain text. If you use it, PHP also needs to be configured not to recognise <? as a the shorthand opening tag - use, so <?php instead.
sources
Dan Tobias: Web standards, DTDs and validation: http://www.dantobias.com/webtips/validators.html
W3C HTML validator: http://validator.w3.org
W3C List of valid DTDs: http://www.w3.org/QA/2002/04/valid-dtd-list.html
Fixing Your Site With the Right DOCTYPE (Alistapart): http://www.alistapart.com/stories/doctype/
Web Standards Project: http://www.webstandards.org
See also: ValidHtml