Pin Me

Selecting the Best Doctype for Your Website

written by: S. R. Obbayi•edited by: Amy Carson•updated: 1/3/2011

Choosing the best DOCTYPE for your website will save your the trouble of loosing sleep over the refusal of your HTML code to work in the way you expect it to, This article will guide you in selecting the best DOCTYPE for your website.

  • slide 1 of 4

    best doctype 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.

  • slide 2 of 4

    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.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

    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 <DIV> is wrong and should be <div>.

    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


    <li>Item One</li>

    <li>Item Two</li>

    <li>Item Three</li>


    you might find


    <li>Item One

    <li>Item Two

    <li>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 <br> you must now add a slash to make it into <br />. Another example is when defining colors. You must always use the pound (#) sign. For example <style>color:#ffffff;</style> and not <style>color:ffffff;</style>.

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

    <!DOCTYPE html>

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

  • slide 3 of 4

    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.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    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.

  • slide 4 of 4


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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    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.


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


    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.