DOCTYPE & DTD

by Joe Gillespie — Oct 1, 2003

In HTML and XHTML, the DocType is a special tag that goes right at the top of the page above <HTML> and warns the browser what's coming.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

This one, for instance, tells the browser that the page uses Extensible HyperText Markup Language - Just like saying "The game is Five Card Stud. Aces are high. Jacks are wild". It lays down the ground rules for the game.

Contained within the DocType declaration, in valid XHTML, the DTD is the Document Type Definition. This defines the particular grammar, rules and syntax that apply to the flavor of XHTML being used.

If you enter the DTD part of the DocType into your browser's URL field, you will find that it links to a file on the W3C site. You can download it and read it in a text editor if you like - but it doesn't make for very interesting reading, it's just a load of rules and regulations. The browser will understand them even if you don't.

What is important is the fact that there are three variants of the DTD.

The most important one is the 'Strict' one.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Ideally, you're encouraged to use this one as it excludes all the leftovers from the past and give the cleanest, most predictable CSS results. On the downside, if your audience aren't using the very latest browsers with good CSS support, it's not at all forgiving and you might not get what you expect.

'Transitional' is a safer bet in the real World, where there are still loads of old browsers about. This one satisfies the widest viewing audience.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

'Frameset' is only employed if your site uses frames. Some still do, but frames have fallen out of favour and fashion. There are better ways to achieve the same effect using CSS.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

In HTML, the DocType and DTD do much the same jobs but a HTML page will validate without a DTD. In XHTML, it's mandatory.

Del.icio.us Digg Technorati Blinklist Furl reddit Design Float