July 18, 2009
The HTML Doctype
If you’ve been following HTML 5, then you’ve seen the new doctype:
<!DOCTYPE HTML>
…compared to the old HTML 4.01 one…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
It starts out the same… but doesn’t have any of the version information. It’s also much easier to remember (has anyone memorised the old one?)
Is it time yet to use the HTML 5 Doctype?
Hold on a second… did I just say HTML 5 doctype? Nothing in it says anything about a version, let alone version 5. According to the draft HTML 5 Specification, the doctype “is a mostly useless, but required, header”. Its only purpose is to convince browsers to render the page in standards mode. From the draft HTML 5 Specification:
DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.
So, where does that leave us now?
To answer the previous question first, yes, we can use the new doctype now. Even Google does on their home page.
If you use the ‘new’ HTML doctype, then you are just saying that the page is HTML (not XHTML or something else), and you want the browser to render your page in standards mode. It doesn’t mean you’re using ‘HTML 5’ — will the doctype change again for HTML 6? Who knows? …but I don’t think it will.
— but you might still want to be careful. On client sites, I would still use the HTML 4.01 Strict Doctype (not XHTML, but that’s another story…). On personal sites, I will use the new HTML doctype — it’s still relatively new, so you need to be prepared to change things if it causes unknown and unpredictable side-effects (but there shouldn’t be).
Could we have been using the <!doctype html> doctype before ‘HTML 5’ even existed? All that really matters is that the browser knows that you’re serving HTML, and it renders the page in standards mode. So, I suppose we could have.
Leave a Comment