The Doctype Declaration

Every HTML document should have a document type declaration. The "doctype" begins the web page and tells the browser how to interpret the coding on the page. It also tells a validator which version of HTML to use in checking the document's syntax.

When you use a CSS file, omitting the document type will throw the browser into "quirks" mode and can give you very unpredictable results. Since CSS is designed to tell the browser how to display the content, why make the browser guess? Add a doctype!

While there are a variety of document types from which to choose, chances are you will want to select from one of four options:

HTML 4.0 Strict

HTML 4.0 Strict is a trimmed down version of HTML 4.0 that emphasizes structure over presentation. Deprecated elements and attributes, frames, and link targets are not allowed. By writing to HTML 4.0 strict, you can achieve accessible, structurally rich documents that easily adapt to style sheets and different browser situations. The document type declaration for HTML 4.0 strict is:

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

HTML 4.0 Transitional

HTML 4.0 Transitional is probably the most "forgiving" of the document types. It allows presentational attributes, some deprecated elements, and link targets. The document type declaration for HTML 4.0 Transitional is:

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

XHTML 1.0 Strict

Most web sites that use CSS for positioning elements will use XHTML rather than HTML coding. The W3C (World Wide Web Consortium) currently recommends using XHTML. This hybrid language looks and works much like HTML, but is based on XML, the web's "super" markup language. XHTML requires a more "logical" document structure.

XHTML 1.0 Strict is an XML version of HTML 4 Strict and is written as follows:

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

It is also recommended that you include the "namespace" information into your opening <html> tag.

XHTML 1.0 Transitional

XHTML 1.0 Transitional is an XML version of HTML 4 Transitional and is written as follows:

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

It is also recommended that you include the "namespace" information into your opening <html> tag.