Using an XML declaration triggers Quirks mode in IE 6

If you use an XHTML doctype in your documents, do not include an XML declaration unless you want Internet Explorer 6 to use its Quirks mode. An XHTML 1.0 Strict doctype with an XML declaration looks like this:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "">

IE 7 and later are not affected and will use Standards mode. Neither are other browsers (except for old versions of Opera).

The most obvious effect of IE 6 using Quirks mode is probably that it will use a broken CSS box model. More info on that can be found in Internet Explorer and the CSS box model.

The XML declaration is optional if you use UTF-8 or UTF-16, so my recommendation is to simply remove it and use the following:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "">

This post is a Quick Tip. Background info is available in Quick Tips for web developers and web designers.

Posted on April 28, 2009 in Quick Tips, CSS, (X)HTML