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?
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.
More Articles by Anthony Lawrence © 2011-04-28 Anthony Lawrence