Post content

Choice of doctype

The “document type declaration” or “doctype” should be the very first thing that appears in an web page. The doctype is not an HTML tag. It is an instruction to the web browser that identifies the version of the markup language the page is written in.

Specifying the doctype is important to ensure that the browser knows what type of document to expect. The doctype therefore specifies which of the standards, set by W3C, for coding webpages you are trying to conform to.

There are a number of choices. There is the choice between HTML and XHTML. Then there is the choice of the different flavours of each, strict or transitional. Researching the differences between these to determine which is the best to use becomes bewildering. There is a whole load of contrary advice and opinion. Some of which gets very technical, particularly relating to MIME types.

I have a lot of sympathy with those who wish to conform to strict standards and have neatly written code. Also with those who want to use more recent standards and look to the future. My instinct then is to use XHTML strict. This requires you to write better code and have the presentational elements dealt with by CSS. Which is the way it should be.

However, the key thing I have learnt is this;

“Standards are written for validators not web browsers.”

When serving a text/html document all you need a doctype for is to trigger standards mode in the browser. As long as your HTML markup then produces the right result you don’t need to worry. Everything else is just the personal preference of the developer.

So which doctype to use?

Well, while HTML5 is not yet an official standard, it is the direction in which the world is heading. Also, the HTML5 doctype is really simple:

<!DOCTYPE HTML>

So for the future I am going to try using the HTML5 doctype but write my code using XHTML syntax.

specify the doctype in all HTML documents, so that the browser knows what type of document to expect.