tags:

views:

373

answers:

2

It used to be so that documents with doctypes got standards mode, documents without doctypes got quirks mode. But it seems that these days there are some almost-standard modes, different browsers follow different rules etc.

What's the best doctype to use for HTML? Is there any reason not to use the simplest one <!DOCTYPE html>? Most documents don't follow any particular DTD to the letter anyway.

+5  A: 

Going forward and into the future, the HTML5 Doctype would be my recommendation.

<!DOCTYPE HTML>

In practice, the HTML validators pay far more attention to a page's doctype than browsers do anyway.

UPDATE: For those commenters that question the statement immediately above, here is my source for that statement: Webkit Blog. It says:

...beware, the validator looks at your doctype instead of the MIME type, unlike browsers.

Also, FWIW, the recommendation of the Webkit people in the above linked blog is to use an HTML 4.01 transitional doctype, served with mime-type text/html and validated as HTML, not XHTML.

Asaph
Why would you use HTML5 over, say, XHTML 1.0 STRICT?
Robert Harvey
Why would you even use XHTML?
cletus
@cletus - If I have to use multiple namespaces (XHTML + SVG + MathML) then XHTML becomes my best bet.
James Black
@Asaph - When I use XHTML2 it seems the browser pays attention as I loose the ability to use innerHTML as a writable property of elements.
James Black
I would go with HTML5 because it seems to be the latest and greatest, but also because it's what google is using. View source on google.com.
delux247
@James Black: To address your comments about XHTML, I've updated my answer with a link to the Webkit blog. Read through it to understand why they (a browser maker) advise against XHTML.
Asaph
@Asaph - I use a mime type of application/xhtml+xml as shown here (roughly, I didn't use their php code): http://www.workingwith.me.uk/articles/scripting/mimetypes. I use XHTML when I have multiple namespaces, as I don't believe HTML5 will work with that, but, I could be wrong. Otherwise I use HTML5. Use what you need, no more, no less, as I stated in my answer.
James Black
@James Black: doesn't mime type of application/xhtml+xml break IE? The webkit blog link in my answer suggests so. Generally, I agree with your philosophy of use what you need, no more, no less.
Asaph
+1  A: 

What is the simplest you need for the page you are creating?

You should specify which type of webpage you are presenting, so if you are using tables for layouts then HTML 3.1, if using CSS then HTML 4.01.

If you are going to use some of the new features in HTML5, then use that one.

Basically, be specific about what you are doing, to help the browser to render your page in the best way.

James Black
Not to give you a big head or nuthin', but I think a quote here is in order: "Make everything as simple as possible, but not simpler." - Albert Einstein
Rafe Lavelle