What is a doctype?
A doctype is a redundant line of text added to a .html document that will needlessly tell the browser what type of content is in the .html file. Your browser is duty bound to ignore the content of this tag, and render your page irregardless of what this tag contains. At most, it tells a code validation program what sort of .html you were trying to write.

Is it ever useful?
Rarely. If you are doing something non-standard (perhaps pasting something in from a non-compliant word-processor, you know who you are) you might need to put in an odd doctype.

Should I leave it out?
Unfortunately, no. Like most w3c suggestions, it bloats the document, but unless you are working in an unusual environment, not by enough to make a difference. You may as well write compliant pages.

What doctype are the cool kids using?
The latest fad is blessedly short:

<!DOCTYPE html>

The w3c will be quick to point out that this is NOT a standard yet, but you can be cool and cutting edge with this easy to remember code.

What if my boss wants something traditional?
Well, first, your boss really ought to listen to your suggestions. If not, you have some options:

The previous popular doctype was this annoyingly long one:

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

This one claims that your code will be formatted following both XML and HTML rules. Not that there is anything wrong with that...

You would probably almost never need this one:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

You might need to use one of these transitional ones if you are supporting older code:

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

If you use frames, which can be really handy, you might need one of these two:

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

If you want to see the whole list, including a few obscure ones, check here.

Related topic character encoding.

What do you think?

Name (optional)

Email (optional)

Your comment (optional, but helpful)