APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Why Validate Doctypes?


If you looked at the website source of most pages here, you'd find that they begin with this text:

"-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">

A person unfamilar with web site creation might reasonably ask "Why?". Interestingly enough, a person very well versed in web site compliance might ask the same question, though for a different reason.

For the naive questioner, I'll simply refer them to the W3C.org pages that attempts to explain why you need that text at all. I don't think that provides an entirely satisfactory answer, but there it is. Basically, the best answer is that you need a Doctype because your pages may not display correctly if you do not have one.

With that out of the way, the more important question is "Which Doctype?". As you can see above, I chose "XHTML Transitional". Why not "Strict"?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
 xml:lang="en" lang="en">

For that matter, why XHTML at all? Why not just this?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

That comes from http://apple.com, and by the way, as I write this, Apple's home page does NOT validate: http://validator.w3.org/check?verbose=1&uri=http://Fwww.apple.com/. That's hardly unusual, though: http://www.oreilly.com, a strong supporter of standards, uses this on their home page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

And, like Apple, at the moment I am writing this, that page also fails validation: http://validator.w3.org/check?verbose=1&uri=http://www.oreilly.com/F. So much for standards.

Lest you think I am casting aspersions at Apple and O'Reilly, be assured that you can easily find non-validating pages at this site. Most of them will be older stuff that I haven't yet got around to fixing, but even the newest pages sometimes have validation issues. I do try to keep compliant, but it's a constant battle.

But let's get back to that "Why?". Why did I choose XHTML Transitional? Why not "Strict" and why XHTML at all?

Well, I chose XHTML because someday that's what the web will be. That is, plain old HTML will be deprecated and mostly unused. Eventally (don't hold your breath) there could come a day when browsers won't accept anything but XHTML. That's probably true enough, but I'm being a bit silly: I'll be sixty years old in a few months, and it's extremely unlikely that I'll live long enough to see XHTML take over the web to that extent. Most likely, if you are old enough to read this, you won't live long enough to see that day either. Also, there isn't a tremendous amount of difference between XHTML and HTML 4.01, but just the same, I went with XHTML.

But why not "Strict"? If you are going to do something, why not do it right? Why stop just short of the ultimate goal?

The answer is "Ads and Javascript". From Google ads to Feedburner stats and everything in between, almost none if it comes close to XHTML Strict compliance. Most of it won't meet XHTML Transitional either, though usually you can fix that with just subsituting "&amp;" for "&'s". Silly as it is, I can come closer to compliance with Transitional.

Honestly, this annoys me, particularly when the offense is grievous and unnecessary. Providing code that would "just work" under any Doctype is impossible, but it's outrageous to see (for example) "<P>" - there's no reason at all for that.

If you are interested in XHTML, I recommend reading the XHTML Tutorial at w3schools.com. As noted above, there are not large differences from clean HTML, with the most important concerns being:

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element

But also as noted, realistically it's probably unimportant - pick the simple HTML Transitional if you want to be compliant but don't want to put a lot of effort into it. For that matter, all browsers (with Opera being the only exception I know of) are loaded with work around code that will ignore all manner of sins whether or not you use a Doctype and whether or not your pages are in compliance with what you chose. That extra "unnecessary" code (unnecessary if web sites cared about standards) will almost always "do the right thing" anyway. That's reality, and it will likely remain that way for a long, long time to come.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Why Validate Doctypes in your HTMl pages?

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Anthony Lawrence

Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us