Submitted by Barney (not verified) on Sun, 11/08/2009 - 09:59.
I find DOCTYPEs very interesting (sad but true). In particular, I've always wondered what practical effect they have on browsers - since browsers will do their very best to render even horribly broken HTML, and implement their own deviations from W3C, will an incorrect DOCTYPE have any effect? And since IE has such an abstract understanding of what makes a healthy HTML document, how does it interpret dtds, if at all?
There is a fun fact about IE's behaviour as regards doctypes. Sure you can use an XML doctype before the XHTML doctype to force quirks mode in older IEs, or use a malformed doctype (or none at all). But get this. IE7+ will attempt to download the dtd from the location specified in the DOCTYPE every time. It doesn't even cache it, or actually do anything useful with it (god knows it doesn't respect it). This means that every time anybody using IE7+ loads any HTML page with a doctype, W3.org gets an HTTP request! But this is the punchline: W3's hosted dtds have some browser-sniffing going on on the back end for each incoming HTTP request - if it's a normal, healthy looking one it will simply HTTP respond with the .dtd file. But if it detects IE, it returns a single word: 'NO'. I think this is one of the most hilarious IE deficiencies ever.
A nice way to avoid that stupid (but inconsequential) behaviour and keep everyone happy is to use the HTML5 doctype. It's valid on pretty much any well-formed XHTML document, forward-compatible, produces correct behaviour in all modern browsers, and easier to remember too:
Fun facts
I find DOCTYPEs very interesting (sad but true). In particular, I've always wondered what practical effect they have on browsers - since browsers will do their very best to render even horribly broken HTML, and implement their own deviations from W3C, will an incorrect DOCTYPE have any effect? And since IE has such an abstract understanding of what makes a healthy HTML document, how does it interpret dtds, if at all?
There is a fun fact about IE's behaviour as regards doctypes. Sure you can use an XML doctype before the XHTML doctype to force quirks mode in older IEs, or use a malformed doctype (or none at all). But get this. IE7+ will attempt to download the dtd from the location specified in the DOCTYPE every time. It doesn't even cache it, or actually do anything useful with it (god knows it doesn't respect it). This means that every time anybody using IE7+ loads any HTML page with a doctype, W3.org gets an HTTP request! But this is the punchline: W3's hosted dtds have some browser-sniffing going on on the back end for each incoming HTTP request - if it's a normal, healthy looking one it will simply HTTP respond with the .dtd file. But if it detects IE, it returns a single word: 'NO'. I think this is one of the most hilarious IE deficiencies ever.
A nice way to avoid that stupid (but inconsequential) behaviour and keep everyone happy is to use the HTML5 doctype. It's valid on pretty much any well-formed XHTML document, forward-compatible, produces correct behaviour in all modern browsers, and easier to remember too:
<!DOCTYPE html>