NOTE: This article is super old. As I write this warning in mid-2013, there is only one DOCTYPE that should be used, the HTML5
Aaron Bazinet originally posted this question in the forums.
I'm going to go ahead and say right away I'm not an expert on this subject, but I do find it quite interesting. The first line of every page we design starts with a DOCTYPE, and I have a feeling that most of us don't have a real strong grasp on all that it means.
The code-peakers amongst you will probably notice right away that CSS-Tricks uses XHTML 1.0 Transitional. Yeah that's probably not good, for reasons we'll touch on. To be honest, when I first coded CSS-Tricks, I understood much less than I do now, and I'll likely be changing this soon.
I think the best place to start is in the year 2000 when XHTML 1.0 became the official recommendation of the W3C. It literally was designed as the successor to HTML. So here we are more than 8 years later. We are now at XHTML 1.1 (1.2 is still being worked on, and 2.0 is a long way off). And we are still talking about whether we should be using it at all.
In 2002, there was already talk about how XHTML leads to better living. Then in 2003, the first edition of Jeffrey Zeldman's Designing with Web Standards was released (now in it's 2nd edition, 2006). Many of us probably own and have read this book. To be honest it feels kinda outdated when you read it now because the example seem so basic and the designs seem so old school. But, it's still probably considered to be the closest thing to "The Bible" of web standards. This book is absolutely jam-packed with XHTML lovin'.
So those of us who are fans of Zeldman, A List Apart, Happy Cog and that whole crew, we drank the kool-aid and starting using XHTML. Is that good or bad? I just don't know.
Here are some points to consider:
- XHTML is more like XML. That means your code has to be written a lot cleaner. No uppercase allowed (in tags). Every tag absolutely must be closed. Clean code is good right? I think so. But, not closing a tag can have a lore more dire results than in HTML, that's not good, right?
Because XHTML is more like XML, it's a lot more extensible. Here is what the article XHTML - Myths and Reality has to say:
...This will make it possible for an author to express more structures and richer semantics than is possible with HTML today. In effect XHTML inherits the possibility of supporting more than one language instead of extending HTML in a monolithic fashion, XHTML can be extended through modules, where each module define a specific subset of the language.
This, theoretically, means extension of the language can be done without the need for a browser upgrade.
Hey that sounds pretty cool! But... how many of us will ever use that ability? 0.01%?
- XHTML isn't always interpreted as XHTML. I don't fully understand this yet, but apparently a large numbers of browsers don't take advantage of the fancy things XHTML can do anyway. IE 8 will be the first version of Internet Explorer that supports it all. Doesn't mean that your site will be broken, just means that the code will be interpreted as regular HTML anyway. From what I understand, general consensus is that HTML 4.01 is the way to go for the most widespread support.
- Minor considerations about CSS. Since this is, you know, technically a site about CSS it's worth mentioning there is a little thing to keep in mind about CSS and these different DOCTYPES. In HTML, some tags will automatically get applied to the document, like a <tbody> inside a <table>. So in CSS, you can declare something like "tbody td" and be confident that rule will take effect, even if you leave the tbody out of your code. Not the case in XHTML.
One thing that is for sure, is that there is no clear cut answer. If I had to make up my mind right this second I'd say that HTML 4.01 kinda makes more sense for most regular web designers / web sites. I should also say that I've designed a crapload of websites blindly just using XHTML 1.0 Transitional, they all work and I'm still breathing.
So don't yell at me too bad, but feel free to enlighten me and the rest of us if you know more.
Great reference in the SitePoint forums here.
Oh yeah, and isn't it funny we were discussing HTML 5 vs. XHML 2? Ha.