Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i choose a doctype? 4

Status
Not open for further replies.
HOW DO I CHOOSE A DOCTYPE? this has been reformatted from the original version

As the W3C reminds us, there are many types of HTML in use on the internet. To ensure these documents are displayed correctly, the various programs (browsers, mobile phones, PDAs etc) that view these documents need to know what kind of document structure they contain. These programs look to the Document Type Definition (referred to as a DTD and commonly called a doctype).

The doctype appears as the very first thing on the page that is delivered to the user, allowing the browser agent to make decisions about how to display the page. Whilst a document can still display within a web browser in the absence of a doctype, defining one implies the document is "well formed" and allows a browser to make assumptions that assist it in rendering correctly. It also prevents the browser from making the wrong assumptions and displaying the document in an unexpected "quirks" mode.

So how do you decide what doctype to use? Again, the W3C have provided a list of recommended DTDs for your document but they don’t offer a lot of guidance to the developer in choosing one. In my opinion it comes down to a question of whether you are creating an HTML or an XHTML document.

CHOOSING BETWEEN HTML AND XHTML

Unless you are going to be serving your documents as "text/xml" and loading them into an XML parser to allow your XML tools to manipulate the page, then there is no reason to develop your documents as XHTML. A majority of web pages on the internet are HTML - and this should be the default choice for developing your documents - especially if your web host is serving your pages as "text/html".

FRAMESET, TRANSITIONAL OR STRICT?

If you are developing frameset documents, then the choice is already made for you - you will use a Frameset doctype. The rest of the time you should consider using a Strict doctype which is almost the same as the Transitional doctype, but with the presentation specific elements removed (deprecated).

The big difference between Transitional and Strict doctypes is the seperation of the presentation and content layers within the document. The idea is that you use CSS to define the layout of your document, and rely on well formed HTML to define the content of the document. This ensures that the different programs that may be used to view your document are able to read the content consistently, and apply the appropriate presentation layer (via CSS).

WHEN SHOULD YOU USE A TRANSITIONAL DOCTYPE?

The Transitional doctype is appropriate if you are working on an existing HTML document that contains presentational elements (like the <center>, and <font> tags). These tags were totally acceptable for the older HTML 3.2 definition (where the presentation and content layers were freely combined) and many sites still contain documents that have not been "upgraded" to use the most current standards.

If you are starting a new site, then you should be using a Strict doctype rather than a Transitional one.

SO TELL ME WHAT TO DO!

To summarise, I would suggest that you use the following doctype for each of the following "common" development scenarios:
[ul]
[li]Frameset HTML 4.01 - when maintaining or updating a frameset HTML document[/li]
[li]Transitional HTML 4.01 - when maintaining or updating an old HTML document that contains deprecated tags[/li]
[li]Strict HTML 4.01 - when building a new site which seperates the presentation and content layers[/li]
[li]Frameset XHTML 1.0 - when maintaining or updating an HTML frameset XHTML document[/li]
[li]Transitional XHTML 1.0 - when building or updating a site that needs to support HTML presentation layer tags[/li]
[li]Strict XHTML - when building a new site that will be manipulated by an XML parser and served as "text/xml"[/li]
[/ul]
The decision of whether to use Strict XHTML 1.0 or XHTML 1.1 is left to the reader. If you are developing Strict XHTML documents and serving them to a wide audience, you should have already made this decision based on the audience and the technology being used to serve (and read/parse) the documents.

FURTHERMORE:
[ul]
[li]this document in it's original form[/li]
[li]list of recommended DTDs from the W3C[/li]
[/ul]



[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Only if a page is to be used via XML in some way should you use XHTML, so XHTML isn't set to replace HTML then, which I was under the impression it was especially when W3C say
XHTML is the successor of HTML
, nothing is ever plain and simple is it!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I was as surprised as you! I did this article because I couldn't honestly say why I was using a certain doctype... and nobody I asked was able to give me an adequate answer (lots of opinions... no facts).

So it was a surprise to me (I've been gearing toward XHTML 1.1 in my recent work). The result now is that I can back up my statements to use a particular doctype with a little more comfort.

I'm currently looking at the <script> tag and will put something together to answer the question "What goes in my <script> tag?"

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Echoing the comment I left on the original article:

Nice writeup.
However, I would say that even if your host isn’t serving pages as “text/xml” right now they may in future.
To that end, and by the same token as it’s prudent to use a strict doctype when starting a brand new project, I would say that it’s sensible to develop in XHTML rather than HTML.
Additionally, XHTML promotes much neater coding.

Maybe I’m wrong… dunno… personal feeling.

Foamcow Heavy Industries - Web design and ranting
Buy Languedoc wines in the UK
 
So some problems could actually be caused by having a doctype of XHTML because it puts the browser in "Quirks Mode".

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
That article that Dan linked was excellent. The table showing quirk mode and standard mode support across browsers and doctypes was really interesting.

Fortunately... my recommendations still hold some weight after reading it: use HTML 4.01 Strict (with a full doctype) and you'll get the best support (and since MacIE is now officially about to be defunct it's hardly a big problem that it switches to quirks mode).

There are some good notes about serving XHTML and "text/html" and the effects of that as well.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top