I regularly tidy up web pages containing html errors and one of the most common is the lack of doctype information, which is supposed to be the first element on the page, prior to the opening tag. It’s the stuff that looks like this …

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>

So what is this for and do you need it?

Well the good news is that leaving out this information will not cause your page to fail to load or fall apart in a heap, but the bad news is that you are likely to get unpredictable results with different browsers.

One of the most frustrating challenges faced by any web developer today is producing code that will render correctly in the many browsers and versions in use. Including the correct doctype on your pages is a must in minimalising problems.

The doctype declaration is not an HTML tag but an instruction to the visitor’s web browser about what version of the markup language the page uses. The doctype’s role is to specify which version of HTML the browser should expect and the browser uses this information to decide how to render the contents on your screen.

The bad news is that if you omit it from your pages, then the browser makes assumptions about how to render your pages.

We’ve all had the frustrating experience where a file created in an earlier version of a software program will not work in a newer one or works unpredictably, right? Every time that Microsoft releases a new version of their Office suite, I’m inundated with calls from people with problems. There are features that did not exist in earlier versions that cause compatibility problems requiring patches or converters to be installed.

Similarly, HTML has many different versions, the latest of which is XHTML. You’ll be pleased to know that unlike the Office example, the HTML language was designed to avoid these issues from occurring.

I use the doctype shown above in all my web pages and it instructs the browser that we’re using XHTML 1.0 transitional and provides a URL for the W3C specification for XHTML 1.0 transitional which the browser can refer.

You can find out more about the different doctypes and their meanings etc. from the following site which contains lots of excellent information - http://www.w3schools.com/tags/tag_doctype.asp

Like this post? Subscribe to my RSS feed and get loads more!