XHTML DOCTYPE Declarations
Every Strictly Conforming XHTML Document must begin with a DOCTYPE declaration. Although this declaration looks like it might be a tag, it's actually not—it is what it is: a DOCTYPE declaration.
What this little bit of text does is identify itself as HTML, and use a Formal Public Identifier to associate itself with one of three openly available (public) Document Type Definitions, which are the standard declarations of permissible tags and other things. Or, in plain English, it tells human users looking at your document's code and user agents (browsers, cell phones) trying to parse your code what type of document you're delivering, and what elements, attributes, and values ought to appear there.
While you don't need to know all of the preceding information, you must know that there are three Public DTDs available for XHTML 1.0: Frameset, Transitional, and Strict. I've provided XHTML 1.0 Transitional and XHTML 1.0 Strict DOCTYPE documents below; I've omitted the Frameset one because frames are an abomination that need to disappear. The DOCTYPE declaration must appear before the root document element, which is html.
The Sample DOCTYPE Files
To view the code, click these links and choose either View > Source or View > Page Source in your Web browser (different browers have different commands, but they're always located in the View menu):
Which to Use? Transitional or Strict?
The Strict DOCTYPE is the gold standard; the rest of the Sustainable Web Design resource assumes that you want to do right by your family's honor and use the Strict DOCTYPE. Although it sounds about as kind as a ruler-wielding schoolmaster, the Strict version is really our friend. If I were naming the DOCTYPEs, I'd have called Strict "No BS" or something like that. Use it, learn to love it.
The Whole Thing, With Comments
So, now that we've settled on a DOCTYPE, it's time to look at the rest of the basic XHTML document, which you can by opening this link, and choosing View Page Source or View Source in your Web browser. All of the elements have been commented on in the document itself.
Updated on Mon. Apr. 9 2007 at 09:44PM