HTML <!DOCTYPE> declaration

The <!DOCTYPE> declaration is the very first thing in a document, even before the <html> tag. It informs the web browser what type of document your webpage will be.

There are three document types specified in HTML and XHTML which are Strict, Transitional, and Frameset. The difference between the HTML and XHTML document types is that for the HTML document types your code does not necessarily have to adhere to proper syntax rules, while for XHTML it must.

!DOCTYPE Examples

HTML Strict document

Contains no deprecated elements or attributes and no frames.

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

HTML Transitional document

Contains all elements and attributes (including the deprecated ones), but no frames.

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

HTML Frameset document

Same as HTML transitional but uses frames.

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

Strict XHTML document

Contains no deprecated elements or attributes and no frames AND must adhere to proper XHTML syntax rules.

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

Transitional XHTML document

Contains all elements and attributes (including the deprecated ones), but no frames AND must adhere to proper XHTML syntax rules.

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

Frameset XHTML document

Same as XHTML transitional but uses frames.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-frameset.dtd">

XHTML 1.1 document

Same as XHTML Strict but lets you add XHTML modules.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/ xhtml11/DTD/xhtml11.dtd">

An entire document using the XHTML strict document type

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>This is a strict XHTML document</title> </head> <body> <p> HTML is greatness! </p> </body> </html>

Tips & notes

Make it a habit of always including the !DOCTYPE declaration in every webpage you create, even offline pages. Including the !DOCTYPE declaration in every page results in less validation errors which means less time spent fixing errors which means more time for fun happy things that you like (besides writing code, of course).

Use the W3C's webpage validator to validate yourpages.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation