How to choose a DOCTYPE

by Rekha 2010-02-08 18:37:33

There are different versions of HTML in use on the Web. When you pick one for an HTML document, you are picking a DOCTYPE, also known as a DTD or Document Type Definition. A DTD defines the rules that apply to any particular flavor of HTML. The following steps will help you choose the right DOCTYPE.

Web browsers use DOCTYPES to determine which rendering mode they should use to display your web page. Using a DOCTYPE properly will ensure that browsers render your page the way you want. If you want to check how well you are doing, use a validator. Markup validators look at the DOCTYPE to determine which rules they should check the document against.



This part: "-//W3C//DTD HTML 4.01//EN" tells you that this is a DTD document published by the W3C, that the DTD describes HTML version 4.01 and that the language used in the DTD is English.

This part: "http://www.w3.org/TR/html4/strict.dtd" is a URL that points to the DTD document used for this DOCTYPE.


If you don't provide a DOCTYPE at the beginning of your HTML document, browsers will render it any old way they want. This is sometimes called DOCTYPE switching. If the browser doesn't get any instructions about which set of rules to use in the form of a DOCTYPE, then most browsers switch back to the past to render the document using whatever rules remain from their quirky and murky past--which is why this mode of rendering is referred to as "Quirks mode."

The DOCTYPE shown above is a transitional type of HTML. To really be in line with standards you can use a strict type of HTML. Here are the HTML and XHTML strict DOCTYPES.



Once you have a DOCTYPE selected and declared on the HTML page, you need to make sure you are following the rules for the particular DTD you picked. You do this using a validator.

Tagged in:

1463
like
0
dislike
0
mail
flag

You must LOGIN to add comments