Html – Which HTML DocType

doctypehtml

I was asked today by a senior developer which doctype I'd use if I was going to write something (personal / non-commercial) for the open web.

I responded, <!doctype html>, to which I was greeted with a look of shock, horror and surprise and then asked to explain myself.

To my mind, it's a good candidate because current browsers (IE, FF, Opera, Safari) will look at it and switch the content into standards mode – even though they don't implement HTML5. If I want to actually take advantage of HTML5 elements, I can use some javascript to create a reference to those tags not recognised by, say, IE (e.g. document.createElement('article');) and then work with them as if they were native parts of the DOM.

Was this really such a bad answer? What would you have answered and why?

Best Answer

While <!doctype html> is perfectly fine, the WHAT-WG recommendation is to use <!DOCTYPE html>, just in case you end up serving the document as XHTML5 (in which case the capitalisation becomes important).

@David Dorward (unable to comment yet, so…) I disagree with your representation of HTML5. While the new stuff (structural elements etc) are presently poorly supported by browsers, HTML5 is 90% HTML4 with defined error handling (finally). Browsers parse HTML5 the same as HTML4, so assuming you don’t use structural elements (div still works) the differences are minimal. Validator.nu gives better results than W3’s HTML4.1 Strict validator, is being more rapidly developed, and is based on a more detailed spec.

My advice would be to ignore the new things in HTML5 for the moment and treat it as a more precise spec for HTML4. There are no disadvantages and several benefits.