IE6 & IE7 Doctypes problem

All browsers have their flaws, that’s for sure. But sometimes you see pure stupidity, and then it might be worth writing something about it.

If a web page doesn’t have a doctype, it usually means that the page is either very old or created by someone that don’t care or doesn’t know anything about doctypes. The strange thing though is that Internet Explorer treats those pages as something completely different than normal, modern web pages. If you don’t add a doctype to your HTML document, Internet Explorer will not rely on it’s rendering rules any more. For example: If you set both a width and a padding to an element, normal browser rendering makes the total width of the object to be width+left padding+right padding.

.box {
padding: 10px;
width: 200px;
}

The total width of .box becomes 220px. However, without a Doctype to rely on, Internet Explorer does not default to a simple Doctype like HTML 4.01 Transitional which would follow this rule. Instead it decides that the page is not worth a second chance, and some rules are rendered incorrectly. In this example, .box would actually become 200 pixels wide according to IE’s rendering.

You might think that this is not a big deal, but consider that other browsers are smarter than this, which makes the crossbrowser rendering of the web page a mess. It is also a fairly unknown and “not so easy to discover” kind of bug which makes it even harder.

Read about the existing Doctypes and why you should use them over at A List Apart: Doctypes.

Leave a comment

Your email address will not be published. Required fields are marked *