APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Websites, Blogging > Why Validate Doctypes in your HTMl pages?
Printer Friendly Version




Why Validate Doctypes?



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"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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"
"http://www.w3.org/TR/html4/loose.dtd">
 

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"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

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.


If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




 I sell and support
 Kerio Mail server
pavatar.jpg

This post tagged:

       - Web/HTML




Unix/Linux Consultants

Skills Tests

Guest Post Here