A Document Type Definition (DTD) is a set of rules that define the document structure in a particular version of XML or (X)HTML. A browser will parse the web page looking for the Document Type (DOCTYPE) Declaration in your CSS code and will use these rules to validate the page.

An example of Document Type (DOCTYPE) Declaration is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The DOCTYPE declaration is included at the start of the (X)HTML document. It is required in order for the page to validate as the browser needs to know which DTD to use in order to process the page correctly.

In the previous example the DTD XHTML 1.0 Transitional is used.

It’s important to validate all the pages and often, especially while coding, in order to find out bugs in your code.

A way to check if an (X)HTML is valid is to use the W3C validator that can be found at the link http://validator.w3.org. I also use the Firefox Web Developer Extension which allows you to do many other useful things as well like to disable the CSS, Javascript, images, cookies, etc.

However, most older browsers did not fully implement the CSS specifications or were developed before the finale release of the specifications. Therefore, many older web pages were built referring to these incomplete or incorrect browsers’ implementations.

To ensure backward compatibility browsers includes two rendering modes: Standards and Quirks mode.

In Standards mode the browsers render a page according to the specifications and in Quirks mode they emulate the behavior of older browsers.

Some browsers (Mozilla and Safari for example) also include an “Almost Standardsmode which attempts to compromise between the two previous modes, trying to emulate some older quirks while at same time mostly conforming to the specifications.

Basically an XHTML document containing a fully formed DOCTYPE is rendered in Standards mode. An HTML 4.01 document with Strict DTD (with or without URI) is rendered also in Standards mode, with Transitional DTD + URI is rendered in Standards mode, while with transitional DTD without URI is rendered in Quirks mode.

So if you wrote good CSS but yor DOCTYPE is uncorrect, your page may not be rendered in the desired way or not be rendered at all. Therefore it’s very important to include a fully formed DOCTYPE declaration on every page of the website!

N.B. IE6 requires this declaration to be the first line of the (X)HTML code. If not it switches to Quirks mode.

Share
Tagged with: browserCSSdoctypeDTDhtmltutorialvalidatorw3cxml
 

3 Responses to “Document Type Definition (DTD) and DOCTYPE Declaration.”

    Currently it looks like Movable Type is the best blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?

  1. 79.Hiya, I’m really glad I have found this information. Nowadays bloggers publish only about gossips and net and this is actually irritating. A good blog with interesting content, this is what I need. Thanks for keeping this site, I’ll be visiting it. Do you do newsletters? Can’t find it.

  2. Hi, I am writing from Perth, Australia. Thanks for the interesting article. It helped me a lot with my TAFE cooking research :)

  3. Elma Boesen says:

    79.Hiya, I’m really glad I have found this information. Nowadays bloggers publish only about gossips and net and this is actually irritating. A good blog with interesting content, this is what I need. Thanks for keeping this site, I’ll be visiting it. Do you do newsletters? Can’t find it.

  4. Roger Bamber says:

    Hi, I am writing from Perth, Australia. Thanks for the interesting article. It helped me a lot with my TAFE cooking research :)

  5. -->

Leave a Reply