tags:

views:

434

answers:

7

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?

+2  A: 

<!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/

The MYYN
+1  A: 

Was this really such a bad answer?

<!DOCTYPE html> was not a bad answer.

What would you have answered and why?

I'd have given my canned answer about choosing a doctype in general, even though I use <!DOCTYPE html> for my new personal publications.

hsivonen
A: 

HTML5 - experimental, immature QA tools which have a still moving target. (And if you have to use JavaScript (which might be turned off) to get basic structural elements to be recognized then 'eeep!').

XHTML - requires Appendix C hackery to work with Internet Explorer. DTDs are less expressive than HTML 4.

HTML 4 - mature, well tested, mostly supported by browsers, no hackery needed. Can't be parsed by XML tools (but few people use these internally on webpages anyway)

Strict - a good core.

Transitional - Strict plus stuff that (with a couple of exceptions) should be avoided.

Therefore, HTML 4.01 Strict would probably be the best option. Obviously there are exceptions, but I'd make that the starting point.

David Dorward
The question was purely about the doctype, not the actual elements used, though.
Ms2ger
Using a Doctype that doesn't allow elements you are using throws "false" positives when validating. Using a Doctype that allows a large range of elements you intent to not use stops validation from spotting that you (or another member of your team) has by accident. The Doctype is very closely tied to the document, treating it as something independent is silly.
David Dorward
I don't see why this was down-voted. It's a good bulleted summary of the considerations for each doctype.
Phil.Wheeler
“HTML5 - experimental” — paving the cowpaths is hardly experimental. The question only asked about the doctype.
Paul D. Waite
The **QA tools** are experimental and immature.
David Dorward
A: 

I would have answered the same as you because you are correct and I no longer use any other doctype for any new web pages for the reasons given in several good links below (including Anne's answer below cause he works for Opera).

Rob
A: 

First of all I'd say that the Doctype shouldn't have been introduced in the first place. You can't serve cross browser pages with anything other than the text/html mimetype and don't get me started on DTD's.

All the doctype does is to trigger standards mode and is only needed becasue many sites are not built to standards let alone w3c specification. If the doctype has only one purpose then make it simple. HTML5 does exactly that. Developers shouldn't bore us pretending that the doctype has any other meaning than switching standards mode on or off.

The 'senior' developer should get on with his work and stop hassling people about such inane stuff.

Egor Kloos
+4  A: 

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.

Boblet