Tuesday, August 24, 2004

Understanding doctype statements

If you have ever looked at your Blogger template, you may have seen something like this above the HEAD statement:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

The doctype element is usually the first line of any template and gives some specific instructions to the browser on how some things should be treated. On a very basic level, the doctype element tells the browser what version of HTML is being used.

The "EN" part of the element refers to the language used in the markup. This is frequently misunderstood to mean the document is rendered in English. That is not the case and the document itself might be rendered in any language.

An incorrect or inappropriate doctype statement can lead to some unexpected results. We sometimes see questions here on Blogger Forum about problems that are solved by making sure the doctype element is appropriate for the document. In other words, you shouldn't blindly copy templates without having some understanding of how this works. For a very good explanation of the doctype element, take a look at the O'Reilley Net Web Devcenter. Here's an example:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

This DOCTYPE claims that the document is a strict document; that is, it is authored according to a strict adherence to the W3C specification, and uses no presentational markup. Upon seeing this, IE5/Mac will kick its rendering engine into standards mode, so that your document will be displayed according to the W3C standards. This affects IE5/Mac's handling of both CSS and HTML.