Go to any CSS related forum and look at the code people are posting there and you will notice that most of the time the reason for strange and bizarre browser renditions are down to an incorrect DocType Definition (DTD).
A little about DTD
HTML actually comes in a variety of flavours and is not just plain old HTML as many people think it is. Typical types include HTML 4.01 Strict, HTML 4.01 Transitional, XHTML 1.0 Strict and the list goes on.
Why use a DTD?
Web browsers are capable of interpreting most types of DocType or DTD, so you need to tell them which one your website code is using.
So what DocTypes are available?
Loads, take a look at the full list on the W3C website - list of doctypes.
What do I do with my DTD?
Put it at the top of every page, the very first thing the browser sees to enable the browser to parse the remainder of the page as you indent it to.
Confused?
Initially DTD seems confusing but once you get your head around it everything falls into place. There are lots of tutorials on DTD’s on the web, one of the most popular being A List Apart so I won`t go too deep into it. Basically a DTD tells the web browser how to interpret your code.
Don`t want to specify a DocType?
Then you are a very foolish person. failure to display a DTD will force the browser into ‘quirks‘ mode. This is a barebones mode that will probably cause your site to do all sorts of funny things. A DocType is also crucial for validation, don`t display a doctype and your site won`t validate, simple as that! Oh and specify the wrong DocType? Quirks mode is for you then!
How to use a DocType
OK, we know what a DocType is, why it is used and where to put it in your website. But which one do we go for and how do we use it?
there are two main types of DocType you might want to use; HTML Strict and HTML Transitional. Here is what version 4.01 of each of these DocTypes specifies:
HTML 4.01 Strict
The HTML 4.01 Strict DocType includes all elements and attributes that have not been deprecated.
HTML 4.01 Transitional
The HTML 4.01 Transitional DocType includes everything in the strict DTD plus deprecated elements and attributes.
There are also xHTML versions of the above which ideally everyone should be adhering to but in reality most can`t be bothered.
So decide which you want to use and implement it correctly to ensure all your coding efforts don`t go to waste, good luck
0 Responses to “Using the correct DocType Definition (DTD)”