If you don’t already know, a doctype is a declaration that goes at the very top of your HTML pages. The main reason most people have this declaration is to switch among rendering methods, although you can also serve your pages as text/xml to achieve the same effect (more on that later).

There are several doctypes to choose from, depending on what you’re doing. The first ones deal with versions of HTML back to 2.0, and include “modes”, such as strict, transition, and frameset. A lot of attention has come to the newer XHTML doctype in the last few years, for various reasons. Some has to do with elitism, I suppose, but I think the majority seems to come from bandwagoning instead of from research. So, how do you choose which one is right for your website?

Why do we even use DOCTYPEs?

First of all, it’s important to understand why we have the doctype declaration at all. Essential, the doctype is a reference to a structure, list of elements, and list of attributes that are available to a certain version of HTML. Theoretically, browsers are supposed to use that reference to comprehend elements and attributes that are found while parsing an HTML document. In reality, browsers have their own “cached” reference that they validate against to distinguish elements.

Benefits of using DOCTYPEs

So what benefit does the doctype get you right now? Well, it gives you an easy way to change among rendering methods, and can help when you’re checking your document against a markup validator, since the validator will most likely verify the HTML against the DTD it finds from the doctype reference.

There has to be some other reason why you would use one doctype over the other though, right? Well, yes. The XHTML doctype, when adhered to, forces the HTML to conform to XML standards (hence the name), and can be served as XML. Theoretically, that would allow people to extend their XHTML with other cool W3C standards like MathML and SVG right in line with the rest of their markup, whereas HTML 4.0 requires authors to use an image, or a plug-in to display the math markup or SVG object. If this were how things actually worked, then I would jump directly onto the XHTML bandwagon.

XHTML is too advanced for the current state

But here’s why it’s too good to be true. For one, it must be served as application/xhtml+xml to take advantage of the above-said features. That point brings us to our next problem: older browsers cannot recognize the new features, and will either break or badly malform the content. IE6, for example, cannot handle the application/xhtml+xml mime type in the first place, although there are workarounds; other browsers will break upon seeing the inevitably invalid code, as the pages were probably made for lax HTML standards, not strict XHTML. Even if not, error handling is very poor for XML across the board for browsers in use today.

This brings us to why people really use XHTML (or what passes as it): standardization across documents. Developers (understandably) want lowercase tags, quoted attributes, closed tags, and any other consistencies XHTML offers that I’m leaving out. In my opinion, the important ones here are quoted attributes and closed tags, which can be enforced by using any strict doctype, whether it be HTML or XHTML. Lowercase tag names can be enforced with internal standards documents.

The differences among DOCTYPE modes

The last point touches on it, but I’d like to go into more depth about doctype modes: strict, transitional, and frameset. Let’s totally throw out the frameset mode, as you really, really shouldn’t be using frames at this point. Use server-side includes, templating, or a content management system if you’re wanting to have a standard header, footer, navigation, whatever. That leaves us with strict and transitional. If you’re just now getting the hang of writing standards-based HTML and CSS, or are converting an old system to CSS templates, transitional is fine. But that’s just what it is: transitional. Once you have the hang of it or have the opportunity to rewrite, move on to the strict doctype. See Roger Johannson’s 24 ways article for the differences, and more info ยป.

Recommendation: use HTML 4.01 Strict

So when do you use certain doctypes? For now, I recommend using the HTML 4.01 doctype. Not necessarily because it’s the best DTD in the world, but because XHTML is still in its infancy, and currently isn’t well-supported by browsers when it comes to rendering and error checking. It’s good to revisit this argument every once in a while to see if it’s worth the change yet. In the meantime, you have the choice between transitional and strict modes. Only use transitional if you’re truly in a transition period.

One final note: use the URL reference in the doctype. For example: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/x1/DTD/x1-strict.dtd”> instead of <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”>. This allows future user agents to validate against that DTD so that 20 years from now, if your website is still around, user agents that conform to the W3C standards will be able to at least interpret your web pages.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>