Choosing a DOCTYPE Tutorial
Made by: Nick
DOCTYPEsAccording to the World Wide Web Consortium (W3C), each (X)HTML document needs to include a document type declaration (DOCTYPE). This DOCTYPE has to be placed at the very start of any (X)HTML document and “tells” any tool which processes (X)HTML documents (browsers, validator, etc) which version of (X)HTML to use to render the page. If you do not use a DOCTYPE at all the browser will render the page in quirks mode instead of standards mode which will usually give you all sorts of strange results as each browser uses different rendering engines in their quirks mode.
Common DOCTYPEsIt is more than likely you will be looking to use one of the common DOCTYPEs below but just incase none of these apply to the document your working on the W3C have a list of all the available DOCTYPEs for you to use.
HTML 4.01 Strict< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
This is a trimmed down version of HTML 4.01 which concentrates on structure over presentation. Depreciated elements and attributes are not allowed in this rendering engine. Using HTML 4.01 strict allows the author to achieve fully accessible documents with great structure that will adapt easily to any style sheet applied. Although HTML 4.01 Strict documents may look fairly bland in very old browsers not capable of using style sheets, there are not many people still using those browsers, so it does not pose a serious problem anymore.
HTML 4.01 Transitional
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
This is the same as HTML 4.01 Strict but allows you to use presentational attributes, depreciated elements and link attributes.
HTML 4.01 Frameset
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
This is a version of HTML 4.01 that is only to be used in documents using frames.
XHTML 1.0 Strict
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
This is an XML version of HTML 4.01 Strict.
XHTML 1.0 Transitional
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
This is an XML version of HTML 4.01 Transitional.
XHTML 1.0 Frameset
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
This is an XML version of HTML 4.01 Frameset.
But, Which One do I Use?When creating a (X)HTML document it is best to choose the DOCTYPE for the latest version of the language you will be coding in, at the time this article was written the most recent version would be XHTML 1.0 or HTML 4.01.
As for choosing whether to use strict, transitional or frameset it should be fairly straightforward. You should use strict on any document, unless you absolutely have to use a depreciated element/attribute in which case you would use transitional, and of course, if you use frames at all in the document then you will want to use the frameset DOCTYPE.
I hope this helps you to choose your own DOCTYPE and keep you writing standards compliant code.