Why is !DOCTYPE so annoying?

I always knew that !DOCTYPE is pretty important thing (maybe TU Varna have taught me something after all), but I never knew why! Until it cost me 126 errors and 24 warning…

So I did a little research and found this quote, explaining my situation in stackoverflow:

!DOCTYPE is like a seat-belt. The car will behave the same way, no matter if you use it or not. Then how do you know you need it? You won’t know until something goes wrong.

Exactly my case, but still doesn’t explains why…

Well, turned out our browsers have something called Quirks mode – a rendering mode that provides compatibility with Internet Explorer 5 and earlier, in difference with the standard mode, that compiles with W3C and IETF standards.

Basically, without the !DOCTYPE element, we tell our browsers to switch in Quirks mode, which is a bad idea, because there are a lot of differences between the modes. For example, in Quirks mode, some dimensions are calculated differently, the selectors id and class are case-insensitive, the body is the root element and its height is always 100% etc (more examples).

In any case, we all know what IE5 can cause to our web pages. 😀

However, the problems do not stop here. In HTML4 it was possible to use doctypes that were syntactically correct, but still trigger Quirks mode.

That’s why you also need to add the doctype declaration to your HTML documents, with the right syntax, which in HTML5 is:

<!DOCTYPE html>

You may notice it’s kinda short. 🙂 Yeah, because unlike previous HTML versions, in HTML5 a DTD reference it is not required. ^_^

 

 

Alright,

[Happy coding, everyone!] <3

 

 

Leave a Reply