Site always renders in quirks mode? DOCTYPE must be the very first item on page!

Every now and then I'll throw a Response.Write() in my code to do some debugging. It always messes up the entire layout of the page when I do that, but I never really bothered to know why. After all, it’s just a temporary situation.

Turns out that the DOCTYPE declaration must be the very first line in your page or the browser will render in quirks mode. When you use Response.Write() on the page, it puts the output before the DOCTYPE, which will cause the above mentioned issue.

So if you're using Response.Write() for anything, make sure your DOCTYPE is first in line. It's worth mentioning that you should also make sure it's a well-formed, non-quirks, DOCTYPE declaration.

No Comments