Friday, November 28th, 2008

<!doctype html>

Category: HTML

pre>

That is what HTML 5 defines, and Dustin Diaz agrees as he lays down the skinny:

Doctypes have long been in standardista discussions circles. Why to use them. Which one to use. Which one is best. These are all <sarcasm>really fun details</sarcasm> to get into, but the most important aspect of any doctype is simply having one, since without one, you’re stuck in the lovely world of “quirks mode”. If you’re interested in understanding the anatomy of a doctype, then by all means, dive in.

There is really, absolutely no reason you need the rest of the doctype in your declaration unless you’re validating code. Furthermore, it does not mean that your page is even invalid. In the end, it puts your webpages into standards mode, which is what really matters. (Plus it’s easy to memorize ;)

Try it out. It will fix your box model in IE6 and clobber all those other funny gotchas when you’re in quirks mode. Cheers.

Do you concur?

Posted by Dion Almaer at 7:22 am
17 Comments

+++--
3.2 rating from 41 votes

17 Comments »

Comments feed TrackBack URI

Am I the only one to think that a Doctype who fails to clearly specify the type of the document is a very bad idea ?
.
I understand the need of simplification, but you should at least specify which html version you use.
.

Comment by ywg — November 28, 2008

It does make sense in a way, although it does kinda feel wrong – not sure why, just feels wrong :S

Comment by Phunky — November 28, 2008

I think if it had the version number it may be better… i.e.

Surely browsers can just store the location of the most popular and common doctypes and treat that like some kind of shortcut? It would certainly save us the hassle of sticking the really long one in?

Comment by hellweaver666 — November 28, 2008

Damn, forgot to code it up… I meant:

Comment by hellweaver666 — November 28, 2008

Once we ween ourselves away from quirksmode supporting browsers we could drop the doctype completely and rely on server defined content type and/or a meta tag I’m sure

Comment by TNO — November 28, 2008

I’m too afraid to try it out :)

Comment by vsync — November 28, 2008

The whole point of HTML5 is provide a “web compatible” platform. This means a document published now should show OK in 10 years from now, and an HTML5-compliant browser will be able to open HTML6, HTML7, etc. web pages.
What it also means is that a valid HTML5 page will be valid HTML6, valid HTML7, etc.
People don’t care whether their page is valid HTML 2.0, what they care is that it’s “valid HTML” (at the time they publish it and at any later point in time) and that it “just works” in browsers.
Having a version number in the web page encourages browsers to do doctype-sniffing.

See also http://hsivonen.iki.fi/doctype/ for more about doctype sniffing.

Comment by tbroyer — November 28, 2008

This is what google has been using in their search results for a while now.

Comment by aheckmann — November 28, 2008

maybe i should read the article before posting the obvious…

Comment by aheckmann — November 28, 2008

As of very recently http://validator.w3.org/ now (experimentally) checks HTML 5. That means it works from the Firefox Web Developer Toolbar as well.

Comment by smith — November 28, 2008

Hmmm, this looks interesting… I’m gonna try it next time… hope the universe doesn’t collapse on itself :)

Comment by iliad — November 28, 2008

@tbroyer
.
Then how can you validate a document if you don’t know which subset you’ve got to test against ?
.
If tomorrow HTML 6 got the ‘object’ tag de precated, and you can’t tell from the doctype which subset the author intended to use… Does these mean all prior document become unvalid ?

Comment by ywg — November 28, 2008

I like it. If it’s good enough for Google pages, it’s good enough for me.

Comment by Nosredna — November 28, 2008

Thanks for posting this Dion. I wanted to also make this clear as someone pointed out on my blog, is that John Resig pointed this out near the beginning of this year and goes even further in explaining the details, and in reality, this is a good idea.

Even so, it’s been working for Google for the last couple of years.

Comment by ded — November 28, 2008

Nobody knows what the web will be like when people are using HTML 7 or 8. What if developers 20+ years from now would benefit from altering the properties of elements and attributes that go into HTML 5? If versioning is omitted, future developers would be locked into today’s view of how the web should work.

Comment by WillPeavy — November 28, 2008

Ha. While Google’s search results do use this method, they also don’t even have an opening HTML tag. I guess they have the testing resources to ignore standards based development, do you?

Here’s to hoping that no tags are ever deprecated or removed!

Comment by zachleat — December 2, 2008

I’d love to… Someone want to tell WordPress to switch to HTML?

Comment by mrclay — December 18, 2008

Leave a comment

You must be logged in to post a comment.