In a perfect world, all browsers would operate under specific standards allowing web pages to be processed and displayed uniformly across all platforms. Unfortunately, this isn’t a perfect world and different browsers display the same code differently. However, with the creation of the World Wide Web Consortium (W3C) in 1994, we are moving towards a more perfect world. W3C is an international consortium working to develop standards for the World Wide Web. The DOCTYPE tag plays a significant role in moving towards a standards compliant world.
DOCTYPE (stands for “document type declaration”) is used to tell the browser and any validating systems which version of (X)HTML you are using. It must be included at the top of every page (before the <html> tag) in order to specify which set of standards you are following. This ensures your code acts as it’s supposed to and is especially important when using newer techniques such as CSS driven layouts.
Even as W3C Standards are becoming more widely followed (with the growing popularity of newer standards compliant browsers such as Mozilla), there are still issues with backwards compatibility for those who are using older browsers, and those companies who are still not following the W3C standards with their browser implementations (finger pointing directed at Microsoft. MS is currently making strides to solve a lot of these issues with the up-and-coming IE7 but it is still lacking). To ease the transition to standards compliance code, different levels of compliance are available. The specific syntax for each DOCTYPE can be seen below:
Please note: For HTML 4.01 and up, the DOCTYPE tag must include a URL which points to the applicable .dtd file. A full URL is required (http://www.w3.org...).
When deciding which DOCTYPE is best for your code, the first thing you will need to determine is which version of (X)HTML you are using. If you are using HTML 2.0, HTML 3.2 , or XHTML 1.1 your choice is limited since these only have one DOCTYPE available at this time. However, HTML 4.01 and XHTML 1.0 include strict, transitional, and frameset DOCTYPES.
If you happen to leave the DOCTYPE tag out of your code or have incorrect syntax, your browser will operate in Quirks mode. Quirks mode replicates the html rendering in older browsers which offers little support for CSS as we know it today. In order to get your sites to be cross-browser compatible in quirks mode, you will have to incorporate endless hacks. Problems can also arise later if you wish to institute the DOCTYPE tag. With the DOCTYPE tag in place, your browser will now operate in Standards mode. Any hacks that were put in place in order to get your code to work correctly in Quirks mode may throw off the way the site functions in Standards mode and you will either have to undo your earlier hacks or put more hacks in place. Because of this, you will want to use the DOCTYPE tag from the start of development.
So go ahead and make your life easier and pay attention to that easily overlooked DOCTYPE tag. Though it may not solve all cross-browser compatibility issues, it will help lessen the amount of hacks you will need to put in place and put you on the road to standards compliance.
Comments (0)