Using the DOCTYPE Tag

Having trouble with your Web pages? Can't get them to display correctly in your browser? It might be that your page is a little "quirky."  Even if you address all errors in a web page, one problem that many developers overlook is a <DOCTYPE> statement or, if used, failure to use the right one.

************************************************************************

What's New on TheCreativeForum.com - http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,2dv1,boez,i33o,eo9f

Webmasters, check out TheCreativeForum, a Web-based community for the creative professional that allows graphic designers, art directors, commercial photographers and other commercial artists to exchange creative ideas via posting of images and work samples for discussion and critique.

************************************************************************

What's New at InternetNews.com:

Navigator's Beta Nods to IE, Firefox http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,brqo,3ubw,i33o,eo9f Netscape returns with latest version of Navigator and
offers both IE and Firefox features.

Add-ons Extend Firefox Growth http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,fuyu,9s51,i33o,eo9f  The online, grass-roots movement of the Mozilla browser
is creating a buzz for the extensions that make it even better.

Microsoft Swats at Phony COAs  http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,e0ra,62g3,i33o,eo9f   Redmond sues traffickers in sham certificates of authenticity.

New Browser Flaw Out   http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,43li,ih8x,i33o,eo9f   And for once, Internet Explorer isn't the only vulnerable one.

'Tis Also the Season for Online Security Warnings http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,35ga,26vb,i33o,eo9f  Online scammers are following the record numbers of shoppers online.

/-------------------------------------------------------------------\

Search Engine Strategies Conference & Expo 2004, the premier event for search engine marketing & optimization, returns to Chicago December 13-16, 2004. Be part of this exclusive gathering of search professionals that features world-renowned search engine expert Danny Sullivan. Learn the basics & practical knowledge of search engine marketing and fully understand how search engines interact with your Web site & ways to improve your listings. Register early & save! http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,57qm,5ay6,i33o,eo9f

************************************************************************

Using the DOCTYPE Tag

Having trouble with your Web pages? Can't get them to display correctly in your browser? It might be that your page is a little "quirky." Even if you address all errors in a web page, one problem that many developers overlook is a <DOCTYPE> statement or, if used, failure to use the right one.

By Lee Underwood

Having trouble with your Web pages? Can't get them to display correctly in your browser? It might be that your page is a little "quirky."

There are several reasons why Web pages do not display properly, such as omitting a required end tag, improperly formatting a table, JavaScript errors, CSS errors, incorrect server requests, etc. Often, these errors happen because Web developers do not take the time to validate their work. In other cases they are a result of a lack of knowledge regarding the proper formatting and coding of Web pages.

Even if you take care of all these errors, something else may be causing your Web pages to display incorrectly or even not at all: failure to use a <DOCTYPE> statement or, if used, failure to use the right one.

A large number of Web pages don't use the <DOCTYPE> statement (Interestingly, many of them are Web development sites). Does it really make a difference? For the most part, not much. But if you want to make sure your Web site renders correctly in various browsers, then it's best to use it. You'll also need it if you plan on validating (http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,6t6f,im8h,i33o,eo9f ) your Web pages.

The Modes
In an effort to contend with Web pages written for older browsers, the newer browser versions (Mozilla-based browsers, Netscape 7, Windows Internet Explorer 6, Mac Internet Explorer 5, Opera 7, and Safari) have two types of presentation modes: standard and quirks. Using the standard mode, the browser tries to follow W3C recommendations. When the browser goes into quirks mode, it's trying to emulate an older version of the browser. This could cause the browser to ignore your page's style sheets and render the page unusable (Mozilla and Safari also have a third mode: almost standards modes, which mainly pertains to the vertical sizing of tables).

What Is It?
The <DOCTYPE> declaration tells the browser what version of (X)HTML is being used so it will know how to display the page. The declaration may also provide a link to a text file (i.e., the loose DTD) (http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,4mb6,ksnt,i33o,eo9f ) which the browser uses to obtain further information. It's similar to having a tune-up done on your car. In order to perform it correctly, the mechanic must know the make, model, and year of the car. He must also know how many cylinders the engine has and its horsepower. Once he knows this, he can move forward and properly tune the engine.

The Specs
The W3C HTML 4.01 (http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,etk8,5zky,i33o,eo9f) and XHTML 1.0 ( http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,dzaz,aq6y,i33o,eo9f)specifications state that the <DOCTYPE> is required in all documents.

The W3C sets the specifications for common protocols used on the Web.  This helps to ensure that each Web site is accessible to the various user agents (browsers/viewers/readers). Technically, there are no standards regarding Web site development in relation to coding.  There are only "specifications," or, as the W3C calls them, "recommendations."  These specifications, however, are seen by most Web developers, as well as the creators of user agents, as being on a par with standards. Most of the current browsers (i.e., Firefox, Opera, Safari) are beginning to closely follow the specifications.

If you follow the recommendations, your Web pages (for the most part) will work correctly. If they don't, it's easier to get help when you are following the rules instead of having to explain the way that you did it. If the specs are not followed, it's more of a hit-and-miss game. You'll need to figure out what works and what doesn't. Then
you'll have to recheck all of your Web pages on all of your Web sites each time a new browser hits the streets to make sure that your non-standard code works in it.

Usage
The <DOCTYPE> declaration must be the very first thing in your document, before the <html> tag. Then, when the browser begins to load the page, it knows how to treat the code within the page.

There are three different document types for HTML 4.01: Strict, Transitional, and Frameset.

The Strict type is used with Cascading Style Sheets and helps to ensure clutter-free coding.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

The Transitional type is used when HTML presentational features are included in the document instead of in a style sheet. This is done to accomodate older browsers that don't support CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

The Frameset type is used in documents that have frames.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN""http://www.w3.org/TR/html4/frameset.dtd">

The same three document types are also used in XHTML 1.0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

Since the <DOCTYPE> declaration is actually a comment tag, it won't confuse older browsers that don't understand the statement.

----------------------------------------------

Additional Information:

Mozilla's DOCTYPE Sniffing http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,j1fi,4rom,i33o,eo9f

Mozilla Quirks Mode Behavior http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,f90n,33km,i33o,eo9f

!DOCTYPE [Internet Explorer] http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,dvxg,i4nj,i33o,eo9f reference/objects/DOCTYPE.asp

Doctypes and Their Respective Layout Mode http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,lyen,bsdu,i33o,eo9f

Validation Tools
http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,7t7v,jmx4,i33o,eo9f

----------------------------------------------

Reprinted from Webreference.com (http://nl.internet.com/ct.html?rtr=on&s=1,19bi,1,7zk3,e2p3,i33o,eo9f)