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

Why Validate Doctypes?


© November 2007 Anthony Lawrence

2007/11/24

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

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://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"
 "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="https://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"
"https://www.w3.org/TR/html4/loose.dtd">
 

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

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

And, like Apple, at the moment I am writing this, that page also fails validation: https://validator.w3.org/check?verbose=1&uri=https://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:




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?


Inexpensive and informative Apple related e-books:

Take Control of iCloud

Take Control of the Mac Command Line with Terminal, Second Edition

Take Control of OS X Server

Take Control of Parallels Desktop 12

El Capitan: A Take Control Crash Course




More Articles by © Anthony Lawrence




Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





Beware of bugs in the above code; I have only proved it correct, not tried it. (Donald Knuth)




Linux posts

Troubleshooting posts


This post tagged:

Web/HTML



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode





SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)
www.SCOsales.com