Jump to content
xisto Community
Sign in to follow this  
jlhaslip

Document Type Declarations And why we use them in html pages

Recommended Posts

This code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd;<html><head>  <title>HTML 4.0 Strict document</title>	<meta http-equiv="content-type"  content="text/html;charset=utf-8" >	<meta http-equiv="Content-Style-Type"  content="text/css" ></head><body>	 <p>... Your HTML content here ...</p>	 <p>... More HTML content here ...</p>  </body></html>

represents a minimum, acceptable web-page according to the W3C which is the organisation that sets the standards for the World Wide Web, or as we call it, the Internet.

In another Tutorial, you can learn about the html code, but in this Tutorial, I wish to emphasis the importance of the DTD or Document Type Declaration, the first line in the sample code above.

 

What it does is tells the Browser that a certain set of rules are to be applied to this page when the Browser renders the document. In this case, the author expects the Browser to use the rules as defined by the W3C for their Html 4.0 Strict documents and the rules are available at the link described in the DTD. (http://forums.xisto.com/no_longer_exists/). This ruleset is public as declared in the DTD.

 

The importance of using a DTD is that 'most' Browsers will display the document in a specific manner, according to the rules as defined by the DTD in use. Of course, there are exceptions and we all know the Browser by name , but let's not get into Browser wars here.

 

Without using a DTD, or using an incorrect one for the code you insert in the page, the Browser will be forced to interpret the code in a manner it deems appropriate, regardless of the known standards, so there will be a larger variation in the Browser rendering of the page in 'Quirks' mode. Without the DTD, each Browser uses its own set of rules and the output can be different in each Browser, so if you are experienceinfg difficulties with cross-browser rendering, also ensure the DTD used in a page is a correct, valid one for the code you have used on the page. The DTD used above is html4.0 Strict. If you intend on using it, ensure your code does not include elements which are invalid for that standard, or expect the Browser to display your page in Quirks Mode, and unpredictable results may occur.

 

There are, of course, other DTD's and a good source of them is at the W3C site.

 

Any questions, post here and I will do my best to answer them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.