Proper DOCTYPEs

Let browsers know what to expect!

Shop for web design and development books here.

Which DOCTYPE to use? Some people don’t even use a doctype, making browsers render in “quirks” mode. When I decided to migrate all my work to XHTML (several years ago), which one to use? I studied the matter a bit and came to an informed decision.

About XHTML

Most web servers won’t serve it as application/xhtml+xml, and most browsers won’t render it even if it is, so there is no reason to use it. Also, the xml prolog messes up some browsers, making them run in “quirks” mode. It may be left out without noticeable harm, if served as HTML using the MIME type text/html.

Be sure to read Is XHTML dead?, and don’t miss this one: Beware of XHTML from webdevout.net.

Update: December 2012

HTML-5 is is the only DOCTYPE you need. It puts 99 percenmt of all browsers in standards mode, and it has a lot of nifty features now being widely used in new web sites.

Update: July 2009

HTML-5 is still a working draft, but there’s no reason not to start using its DOCTYPE now. The declaration is real simple:

<!DOCTYPE html>

After all, the doctype simply makes the browser render in either Quirks or Standards mode, and the above will cause all modern browsers to do the latter. You don’t need a reference to a DTD or namespace. As for validation, it will make the validator use the experimental HTML-5 validator, and it’ll flag some problems like alt=, name=, and etc. Don’t worry about it—they’ll get it all sorted out eventually, and one should not waste time trying to please an experimental validator using a draft DTD. Just write 4.01-Strict code for now, and when it’s finalized, update it to use the new & exciting -5 features.

It’s a good idea to put <head lang="en"> (or whatever lang), and use utf-8 as the charset.

See also, HTML 5 differences from HTML 4, from the W3C, and also this interview with Ian Hickson, editor of the HTML-5 specification.

The Current W3C Official List

Here’s the list, with my (revised) opinions.

Derived from: http://www.w3.org/QA/2002/04/valid-dtd-list.html

XHTML 1.1

Effective use requires XML skills and careful hand-coding. XHTML 1.1 is always served as XML, and must use the MIME type application/xhtml+xml. Browser support is very limited.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

XHTML 1.0 Strict

If web servers will not serve it as application/xhtml+xml and browsers won’t render it even if it is, there is no reason to use it. Also, the xml prolog messes up some browsers, making them run in “quirks” mode. It may be left out without noticeable harm, if served as HTML using the MIME type text/html.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

XHTML 1.0 Transitional

Same as above. It’s served as text/html, with deprecated tags.

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

XHTML 1.0 Frameset

If you must use frames, always use the HTML-4 frameset doctype. Most users are confused and annoyed by frameset sites. CSS provides alternatives, such as scrolling and non-scrolling DIVs.

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

HTML 4.01 Strict

Should be used for new HTML pages. Makes all modern browsers render in Strict (compliance) mode. Includes all elements and attributes that have not been deprecated or do not appear in the frameset documents. Let’s face it—browsers, search engines, and the Consortium will be supporting this for many years, and this should be used until HTML-5 is widespread.

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

HTML 4.01 Transitional

Should never be used—deprecated. It’s also pointless: Makes browsers render in Quirks mode, just like no doctype at all. Still the most popular, because it allows sloppy markup such as unclosed tags and the deprecated markup generated by most wysiwyg editors. Expect browser support for this to fade over the next few years. Note also that using XHTML transitional is no better than HTML transitional, for the reasons above.

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

HTML 4.01 Frameset

If you must use frames, use this. There is no point to using the XHTML frameset if it will be served as text/html.

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

There are several others, some are emerging such as HTML-5, while some are special-purpose, such as XHTML-Basic and the various mobile and mathML DTDs.

Leave a Reply

Your email address will not be published. Required fields are marked *