How to Choose the Best Doctype for Your Website

How to Choose the Best Doctype for Your Website
Page content

Knowing how to select the best DOCTYPE for your website is not difficult at all. In many cases the best DOCTYPE will always be the one you end up choosing. What I mean here is that you do not write your (X)HTML code to match your DOCTYPE. You choose your DOCTYPE to match how well your (X)HTML code conforms to the standards.

Guiding Pointers

Here are a few guiding pointers to use when choosing the best DOCTYPE for your website. You need to determine whether you want to design or redesign your website from scratch or whether you have to maintain legacy code.

If you design a website from scratch then develop it according to the srict standards. Once you have designed your website using the strict standards, you need to choose an appropriate DOCTYPE such as this one.

You would want to use the above DOCTYPE if your HTML code conforms to the strict XHTML standard which has the following sample rules among others.

All tags must be typed in lowercase. Therefore using a tag such as

is wrong and should be
.

All tags must have an opening and a closing tag. With the older none strict standards you can get away with omitting certain tags. It was common to find in lists that the closing tag of the list has been left out. So instead of

  • Item One
  • Item Two
  • Item Three

you might find

  • Item One

  • Item Two

  • Item Three

The second format is not compatible with the strict standards but in none strict standards both would be rendered just fine.

Where you are dealing with single tags such as
you must now add a slash to make it into
. Another example is when defining colors. You must always use the pound (#) sign. For example and not .

To use HTML5 in your website, select the following DOCTYPE.

This allows you to use HTML5 in your web pages and have the HTML5 extensions rendered correctly.

Dealing with Older HTML Code

If you are managing an existing website with legacy code and you cannot alter it, then use a none strict DOCTYPE such as this one.

The DOCTYPE above allows you to have backward compatible HTML in your code without breaking your layout. So with this your web pages are more likely to render even with older HTML code that way you do not need to go back and change the legacy HTML code that you already have. This also happens to be the most popular DOCTYPE in use today.

There may be cases where you may want your website to render and conform to the standards of HTML 3.2 or very old browsers such as IE4 and Netscape 4. In this case the best solution is to use no DOCTYPE at all in your web pages. This will trigger the web browsers into Quirk Mode which allows modern browsers to render your website according to the older standards.

Verdict

To answer the question on which is the best DOCTYPE to use for your website. I would say that using this DOCTYPE.

Gives you the control you need on modern web browsers at the same time allows your browsers to be lenient on your HTML that doesn’t follow the strict standards. If you are targeting mobile devices then you may want to follow the above pointer but instead use the following as the best DOCTYPE for your website.

<!DOCTYPE html PUBLIC

"-//WAPFORUM//DTD XHTML Mobile 1.2//EN"

https://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">

While you decide which DOCTYPE you may want to use, you can also check out the top ten XHTML authoring tools to get you well on your way in designing websites with DOCTYPES in mind.