Website Design Blog - BlueBolt.net
October 10, 2010 – 9:57 am
Which DOCTYPE should I use?
The <DOCTYPE tag is often (and easily) misunderstood and used incorrectly.
It’s not really a surprise. Doctypes can be confusing, and there are plenty of opinions on the subject; some of which will be discussed in this article.
Let’s start by getting to grips with what a doctype actually is – here’s a quote from W3C (World Wide Web Consortium), the only official organisation responsible for trying to tame and standardize the erratic world of website development:
There is not just one type of HTML, there are actually many: HTML 4.01 Strict, HTML 4.01 Transitional, XHTML 1.0 Strict, and many more. All these types of HTML are defined in their respective W3C specifications, but they are also defined in a machine-readable language specifying the legal structure, elements and attributes of a type of HTML.
Such a definition is called a “Document Type Definition”, or, for short, DTD.
This definition amounts to a couple of small lines of code, which visitor’s browsers will use to decide how to interpret the markup. The doctype declaration must be the first line in all pages, appearing before the <html tag.
Doctype declarations are not themselves HTML tags, rather they are merely an instruction to the browser, informing of the markup language used by the web page.
W3C have a page which details a good selection of their recommended doctypes, and is a good bookmark for any web developer keen to meet standards and build websites with integrity.
Here is the link: Recommended W3C Doctype Declarations.
To work out which doctype you need, it is necessary to identify the language you are using. However, it may instead be wise to choose your language based on the ‘best’ doctype that is compatible with the specific nuances of your website.
Optimal doctype selection is subject once again to the familiar battle of compromise between cross-browser support, standards compliance and functionality.
If you are currently working with HTML, it might be worth considering migrating to XHTML, if possible.
Here are some reasons (and tips) given by the WordPress website: HTML to XHTML – WordPress Codex.
If you can’t be bothered to read that page, here are some points summarising the key information it contains:
- If you know HTML, moving to XHTML isn’t that difficult as they are very similar.
- XHTML is stricter than HTML, requiring more refined syntax.
- Some HTML tags and attributes have been depreciated in XHTML (a list comparing doctype capabilities with valid (X)HTML elements can be found here).
- Notable differences between HTML and XHTML include:
- To use XHTML properly, pages must be served with the MIME TYPE: “
application/xhtml+xml“.
That being said, here is another link which explores the topic of HTML vs XHTML in more detail, and is perhaps does not view XHTML quite so favourably:
Beware of XHTML – webdevout.net.
Some notable points described in the article:
- XHTML is not future compatible, and also will not be backwards compatible with XHTML 2. HTML 4.01 is more future compatible as valid pages will still validate when parsed as HTML 5.
- XHTML does not have great cross-browser support – in fact, many browsers will disregard it and process it as regular HTML (especially if the pages do not supply an “
application/xhtml+xml” MIME TYPE as mentioned above). - Internet Explorer 7 and earlier does not support XHTML.
- The stricter rule-set encourages better formed pages.
If you read the page yourself, you will have read the quotes from various credible sources. If not, here are a selection:
- Serving valid HTML 4.01 as text/html ensures the widest browser and search engine support.
The official Mozilla web developer FAQ
- I don’t think XHTML is a realistic option for the masses. HTML5 is it.
HÃ¥kon Wium Lie, CTO of Opera, member of the W3C
- I’m an advocate of using XHTML only in the correct way, which basically means you have to use HTML. Period.
Anne van Kesteren, standards expert at Opera
As you may have realised by now, choosing the most appropriate doctype is far from a black and white decision.
It is imperitive to bear in mind that the link on webdevout.net is now a number of years old, and many browser issues described have been resolved in newer versions. However, the Internet is a big place, and a significant number of users still use outdated browser versions which will be affected.
In any case, the debate of HTML vs XHTML is a topic too detailed for this article to examine any further.
So, which DOCTYPE should you use?
Well – it depends. There is no definitive answer. It will vary based on the limitations imposed by the configuration of the pages you are working with, the criteria you must work to, and preference.
Ideally, sticking with HTML seems to be the safest bet and, overall, is probably the most highly recommended option. One thing which is almost universally agreed is that the STRICT doctype variation should be used whenever possible.
Realistically though, you should not have any problems using XHTML doctypes these days, and should certainly consider it a practical option. If you are going to use XHTML, the following link is essential reading and will ensure your XHTML pages are handled consistently and reliably:
Content-Negotiation Techniques to serve XHTML as text/html and application/xhtml+xml
* This post is currently a work in progress and is likely to be updated in the future and therefore should not be considered a finished article.
Posted in: (X)HTML, Web Development, Web Standards
Tags: doctype, html, standards, validation, xhtml
Leave a Reply
Latest Articles
11/11/10
Toggle Element Visibility with JavaScript
Showing and hiding elements on a web page is a popular technique, and is...
23/10/10
Disable (X)HTML Form Input Autocomplete
The autocomplete feature common to all of today’s major browsers is...
13/10/10
Essential JavaScript Functions and Tips
There have been countless occasions I have expected a JavaScript function...
Pages
Archive
Categories
Tags
Bookmarks
W3C Web Standards
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Nov | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||


