Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which HTML DocType?

Tags:

html

doctype

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?

like image 498
Phil.Wheeler Avatar asked Nov 27 '09 13:11

Phil.Wheeler


2 Answers

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.

like image 155
Oli Studholme Avatar answered Sep 28 '22 19:09

Oli Studholme


<!doctype html> seems fine ..

What's nice about this new DOCTYPE, especially, is that all current browsers (IE, FF, Opera, Safari) will look at it and switch the content into standards mode - even though they don't implement HTML5. This means that you could start writing your web pages using HTML5 today and have them last for a very, very, long time. / http://ejohn.org/blog/html5-doctype/

like image 43
miku Avatar answered Sep 28 '22 18:09

miku