Setting Your DTD

A document type definition, sometimes called a doctype or just DTD, is a text document that contains the rules for how a particular markup language works. Although anyone can create a DTD, Web designers use one of the ones created (and hosted) by the World Wide Web Consortium (Figure 1.10). When the page loads, the browser determines which DTD it uses, and then attempts to render the page based on that doctype.

Figure 1.10. A Web browser displaying the XHTML 1.0 DTDs provided by the World Wide Web Consortium (

You can place a document type declaration at the beginning of your code that includes a reference to the DTD for the markup language your Web page uses (Code 1.1). However, only in the most recent browser versions (Firefox 2, Internet Explorer 7, Safari, and Opera 9) will the doctype have any effect on how the content is displayed. If the doctype is left unspecified, the browser will display the page in Quirks mode, which will behave like a legacy browser. If a recognizable doctype is included, the browser will switch to Strict or Standards mode, which follows the specified standard.

Code 1.1. The doctype tag (which references the DTD file created by the World Wide Web Consortium) is placed at the top of the code.

[View full width]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " /DTD/xhtml1-strict.dtd"> <html xmlns="">      <head>         <title>HTML Strict Doctype</title>      </head>      <body>         This document is XHTML 1.0 Strict.<br />      </body> </html>

There are three DTDs you need to worry about, which can be specified using the doctype tags in either HTML or XHTML (Table 1.4):

  • Strict. Assumes that all styles will be handled by CSS. Thus no formatting tags are allowed.

  • Transitional. Allows you to use a mixture of CSS and legacy HTML formatting to design your page. Sometimes called loose.

  • Frameset. Used with HTML documents used to create framesets.

Table 1.4. Doctypes



HTML Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

HTML Strict


HTML Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" " html4/frameset.dtd">

XHTML Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " transitional.dtd">

XHTML Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " strict.dtd">

XHTML Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" " frameset.dtd">

If you are working with or converting an older HTML site, you might have to resort back to transitional DTD. However, all your new work should use the strict DTD and XHTML. Although this means you will have to be a bit more careful when you code, it takes care of a lot of browser inconsistencies.

Quirks and Standards Mode

Early implementations of CSS in browsers such as Microsoft Internet Explorer 4 and Netscape Navigator 4 were full of bugs, nonstandard behaviors, and even some misinterpretations of the W3C standards. To make pages that looked right with the widest array of browsers, Web designers had to accommodate these CSS quirks. However, as manufacturers have developed new browser versions, they have tried to come closer to the standards without breaking older designs. As a result, most browsers have two or three layout modes:

  • Quirks mode. Used by the browser if it detects that the page is not standards-compliant. This basically renders the page as if it were in one of these older browsers.

  • Standards mode. Uses the standards as defined by the particular browser. These may not be W3C standards, but they may be as close as the browser will get to the standards.

  • Almost Standards mode. Firefox, Safari, and Opera (7.5 and later) have a third mode that uses all of the CSS 2 standards, except for table cell vertical sizing.

Choosing a Doctype

Not including the doctype in your Web page means that newer browsers may not recognize all of the code you are using. Which doctype should you put at the top of your Web page? It depends on how you are coding it:

  • No Doctype. Older Web pages containing a "tag soup" or using quirks from older browsers. If you do not use a doctype modern browsers are forced into into Quirks modea bad idea if you are creating new Web pages because it leaves the interpretation of the code soley at the discretion of the browsers, which can translate into a lot of inconsistencies in the display.

  • XHTML Transitional. Web pages that use some deprecated HTML markup, but can still be validated as XHTML 1.0 Transitional. This puts modern browsers into standards or almost standards mode.

  • XHTML Strict. Web pages that are strictly XHTML and CSS compliant. This doctype validates as XHTML 1.0 Strict and works with the CSS2 box layout model. It switches most modern browsers into Standards mode. If at all possible, this is your best choice.

  • XHTML Frameset. Any Web pages that create a frameset must use this doctype.


  • Earlier browsers that do not recognize DTDs will render the page based on their own definitions, which by default is Quirks mode.

  • Do not include an XML version definition and encoding value above the XHTML DTD:

    <?xml version="1.0" encoding="iso-8859-1"?>

    This causes Internet Explorer to use Quirks mode and will render standards-based content poorly. It will also disrupt dynamic content that uses JavaScript, PHP, ASP, or JSP.

Who Owns CSS?

On January 12, 1999, Microsoft Corp. ( was granted U.S. Patent #5,860,073. This particular patent, titled "Style sheets for publishing system(s)," covers "the use of style sheets in an electronic publishing system." Sound familiar?

The inventors listed in this patent claim to have developed a system whereby "text, or other media such as graphics, is poured into the display region," at which time style sheetsdefined as "a collection of formatting information, such as fonts and tabs"are applied. This patent seems to overlap concepts laid out in the W3C's specifications for CSS and the Extensible Stylesheet Language (XSL), which have been in development since at least 1994.

A brief analysis of the patent shows that it has two major flaws, which the W3C and the Web Standards Project ( have already been quick to point out:

  • "The existence of prior art," referring to the fact that style sheets were proposed with the first Web browsers coming out of CERN laboratories in 1994. In fact, style sheets have been around since the 1960s, when they were used for print publications. At best, Microsoft is a Johnny-come-lately to the concept.

  • The W3C's own licensing ensures that the standards developed under its banner are universally available and royalty-free. Because the W3C first developed the concept of style sheets, its license should hold precedence.

Microsoft had representatives on the committees that created these standards, and its own patent refers to documents produced by the W3C regarding CSS, so it seems highly improbable that this patent would stand up to much scrutiny.

George Olsen of the Web Standards Project questions whether the patent should have been granted in the first place, "because [there] are a number of prior examples of similar technology, including the original proposal for CSS," he says. Also, it is assumed that any organizationMicrosoft includedwith representatives in the W3C will detail any current or pending patents that might affect the W3C standards under consideration, which this patent certainly did. Yet the W3C first heard of the patent on February 4, 1999, when information about the patent was made publicly available. For its part, the W3C presents the claim on its Web site, but attempts to stay neutral as to its validity (

So what does this mean to you? Probably not much. The W3C has published CSS as an open standard, and the genie is already out of the bottle.

CSS, DHTML and Ajax. Visual QuickStart Guide
CSS, DHTML, and Ajax, Fourth Edition
ISBN: 032144325X
EAN: 2147483647
Year: 2006
Pages: 230

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: