DOCTYPE stands for Document Type Declaration and is a requirement for several web documents including HTML and xHTML pages. It must be placed at the beginning of a document and lets the browser (or any other engine interested in making sense of your markup) know what type of technology you are using and which version.
There are many flavors of HTML. For example, the CENTER tag often used for text and images was incorporated to the standards in HTML 3.2, but was deprecated (marked for extinction) in HTML 4, and never made it to xHTML 1.1.
These changes happen for two apparent reasons. The first one seems to be annoying web developers. The second one is a more complicated one: to have a single set of rules that work well and all browsers can render the same – also known as “the impossible”, but we are getting closer.
Basically, tags and properties in the standard definitions are added, moved around and removed in the interest of improving the language; but since it doesn’t make much sense to pretend that the entire world keeps up to speed with the latest changes, when a new set of rules appears it does so with its own DTD (document type declaration) - its own DOCTYPE.
Web developers use the DOCTYPE to specify which version of the standards the site (or page) is being coded in. If you are familiar with HTML 4.01 and haven’t dwelled into xHTML just yet, chances are you want to code your pages in HTML 4.01. I can’t imagine a reason to code your site in HTML 3.2, but you are welcome to do so as well.
In addition to the different versions that appeared through time, HTML 4.01 and xHTML 1.0 are divided into two versions (each): Strict and Transitional. Apparently, once the W3C (World Wide Web Consortium – the group that creates the standards) made their mind about the direction that HTML should take (a complete separation between document structure and appearance), they realized it was too harsh to force developers to adhere to the new specifications immediately so they provided a more forgiving DTD, Transitional, that still accepts deprecated tags and properties.
XHTML 1.0 is basically the same as HTML 4.01 with the addition of requiring valid XML syntax, which translates to code that is cleaner and easier to understand and parse.
XHTML 1.1 is basically the same as xHTML 1.0 Strict with a couple of minor changes.
Now, if you are thinking this is not that complicated, wait a minute, there is another catch. To add to the confusion browsers can run in two general and somewhat documented modes: Quirks and Standards.
Before web standards were truly seen as standards, browsers used to play by their own rules; and they still try to. For IE and FF/Netscape, if the browser can’t tell what DTD you are using (or you haven’t declared one) it will render the page using its own opinion of the way HTML elements should be rendered; this is called Quirks mode. Quirks mode is unpredictable to say the least and it is recommendable to avoid it at all costs.
Also, browsers have their own interpretation of the standards and a little bit of disregard for them; this will also affect the way your page is rendered. Now, is there anything that can be done to force all browsers to render your page exactly the same? You can try suing Microsoft and the Mozilla Foundation, but I don’t think it is going to work. The best solution so far is to pick your DOCTYPE carefully and test your pages thoroughly.
What DOCTYPE to use?
This is a tricky question. The easiest DTD to work with is the HTML 4.01 Transitional because it supports strict code as well as deprecated code.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
But using tags and properties to set the appearance of your content (the FONT tag for instance) will put you in a sort of Quirks mode since the browser has to guess what you are trying to do.
The standards want developers to use CSS (Cascade Style Sheets) to customize the appearance of their pages. CSS is (for the most part) a much more powerful tool for presentation than deprecated HTML.
So, one could recommend the use of Strict HTML 4.01 to prevent browser “guessing” (as much as possible) and CSS to define the appearance of your document.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
Now, xHTML is there for a reason. HTML is - or was - a permissive language that accepted very sloppy code. Browsers in Quirks mode were doing a fantastic job of making sense of that sloppy code, but the audience for web pages is no longer limited to desktop users.
Producing a decent render from bad code requires extra resources that are not always abundant in the new Internet-capable devices such as cellphones, PDAs, etc. There are also more accessibility browsers that need to make sense of your pages, such as screen readers, and don’t rule out search engine spiders and similar automated crawlers.
XHTML uses XML standards to make HTML code cleaner, hence more accessible and easier to deal with. So the best DTD to use would be a Strict xHTML 1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
That is also basically the same as the newer xHTML 1.1, so why not use the latest one instead?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
Finally, there are also other DTDs to choose from, including the older HTML 3.2 and non-HTML markup languages such as MathML and the SVG for graphics. Visit the W3C for a list of recommended DTDs.
Author : Esopo, Read 5175 times, Comments: 0
|Rating : || | Friday, 20. January 2006|
Add new comment/Comments
Are your scripts homeless?
NetBulge.com is devoted to web development. If you are too, then this is the site to house your best scripts and articles. Think about it: exposure, knowledge sharing and free rent.
It almost felt like a joke finding out about this type of server packs after spending a couple of days working hard to setup my personal web server to test my PHP – MySql scripts. Reactor server comes with Apache, PHP, MySql, SQLite, phpMyAdmin, Nuke, etc, and all in an almost plug and play package. If you don’t have one of these in your PC, you better be asking yourself why. – The only draw back: about 38 MBs in size.
NOTE: This is ver1.2 that supports PHP 4. For the latest version visit their homepage.
If you are a coder and were not aware of this site, you have been seriously missing out. At Hotscripts.com you will find a very extensive collection of all sorts of scripts that will ease the work load, serve as a starting point for a new script, or simply serve as an inspiration source for good code programming.http://www.hotscripts.com/