Friday 26 August 2011

HTML5: The importance of !DOCTYPE

   


As our beloved W3C site states:
"When authoring document is HTML or XHTML, it is important to Add a Doctype declaration."
And you perfectly know why... don't you?
Ok... for those of you that don't know why, here's the explanation:
"There is not just one type of HTML, there are actually many: HTML 4.01 Strict, HTML 4.01 Transitional, XHTML 1.0 Strict, and many more. [...] Why specify a doctype? Because it defines which version of (X)HTML your document is actually using, and this is a critical piece of information needed by some tools processing the document. [...] with most families of browsers, a doctype declaration will make a lot of guessing unnecessary, and will thus trigger a "standard" rendering mode."
As you can see it's definitely not trivial. But why am I talking about it? Well, it has to do with HTML5.


According to the aforementioned W3C web site, the following is the doctype declaration list:
HTML 4.01 (Strict, Transitional and Frameset)
XHTML 1.0 (Strict, Transitional and Frameset)
XHTML 1.1 (DTD)
XHTML Basic 1.1
HTML 5

And the last one is the real trick. Let's see an example. HTML 4.01 Strict will be declared with:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
Which is quite clear because it states exactly what our doctype is.
Now let's see how HTML 5 doctype will be declared:
<!DOCTYPE HTML>
See what I mean? Do you understand what might be the problem?

If in an old page you designed few years ago, you haven't declared the doctype, new browsers may think that your document is in HTML5 and thus some "old" features will not work. For example the new Firefox 6 will not understand anchors because the name attribute on the a element is now considered obsolete.

That means we need to state the doctype and be careful with old documents that might not be working as before. Did I scared you? Well... in any case let me know what you think...

0 thoughts:

Post a Comment

Comments are moderated. I apologize if I don't publish comments immediately.

However, I do answer to all the comments.