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 5033 times, Comments: 0
|Rating : || | Friday, 20. January 2006|
Add new comment/Comments
|Your rating : Poor Excellent|
Do you have something to say?
Then say it!
NetBulge.com is devoted to web development. We are always looking for fresh and relevant ideas. If you are a web designer with a voice, this is the place to make it heard.
Many say this antivirus is much better than the leading AV in the market. The least I can say is that AVG performs extremely well and its price (free) is simply unbeatable. If you donít have an antivirus right now or are not pleased with your current level of protection, you should give this one a try.
Most web users are not aware that there are hundreds of radio stations (free) ready for you to pick from. All you need is a player (Winamp), a constant Internet connection and a like for music.http://www.shoutcast.com/waradio.phtml