Working with HTML DOCTYPE Declarations in FrontPage

 

Lisa Wollin
Microsoft Corporation

May 2004

Applies to:
    Microsoft® Office FrontPage® 2003
    Microsoft FrontPage 2002
    Microsoft FrontPage 2000

Summary: Learn what HTML DOCTYPE declarations are and how to determine whether to use them. (7 printed pages)

Contents

Introduction
Determining Which DOCTYPE to Use
List of HTML DOCTYPE Declarations
Changes in HTML Recommendations
Using DOCTYPE Declarations in FrontPage
Resources
Conclusion

Introduction

DOCTYPE is short for Document Type. When you declare the HTML DOCTYPE, you tell the browser which version of HTML that a Web page uses. This is called a DOCTYPE declaration. Because there are multiple versions of HTML, browsers use the DOCTYPE declaration to determine how to render the page.

DOCTYPE declarations are technically optional, and not using one does not cause an error; for example, you can create a Web page without a DOCTYPE declaration, and Microsoft® Internet Explorer, Netscape Navigator, Mozilla, and Opera may all render the page as you intended. However, as your Web pages become more complex, lack of a DOCTYPE declaration can cause pages to render differently than expected or desired. (This is sometimes referred to as "quirks mode.")

In addition, if you design a Web page using one DOCTYPE definition, changing to another DOCTYPE definition might cause the page to display differently. Therefore, determining whether to use a DOCTYPE declaration and which DOCTYPE declaration to use is important if you want all browsers to accurately render your pages.

A DOCTYPE declaration is also necessary if you want to use a validation tool to ensure that your HTML is valid. Web developers can use tools, such as the World Wide Web Consortium (W3C) Markup Validation Service, to validate the HTML in their pages. Valid HTML pages can ensure a minimum level of accessibility. Although a DOCTYPE declaration does not guarantee compliance with accessibility guidelines, validating your Web pages may help to find errors that may cause your Web pages to be inaccessible in various browsers.

A DOCTYPE declaration appears at the top of a Web page before all other elements. A valid DOCTYPE declaration consists of two parts: a definition of the HTML version that a page uses, and a path, also called a Uniform Resource Identifier (URI), to the document type definition (DTD) that defines the HTML version.

Note   A DTD is a document that defines the structure of a markup language as well as elements and attributes. Because HTML is a markup language, the W3C provides DTDs for all HTML versions.

All HTML DOCTYPE declarations begin with the text <!DOCTYPE HTML, but the version and the location of the DTD change depending on the DOCTYPE version that you use.

The following example shows a valid DOCTYPE declaration for the HTML 4.01 Transitional specification, with the version appearing on the first line, and the DTD URI appearing on the second:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

If a DOCTYPE declaration does not include a path to a DTD, the browser assumes the DTD, and display the pages based on that assumption. What this usually means is that the browser assumes that the page uses an outdated HTML specification and renders the page in backward-compatible mode.

Note   Backward-compatible mode means that the browser may display your page using an earlier HTML specification than you intended, which may be fine but may also produce unexpected and undesirable results.

Determining Which DOCTYPE to Use

There are multiple versions of HTML, and each version of HTML may have multiple DTDs because each DTD has a different set of requirements. In fact, just adding any DOCTYPE declaration to your Web pages does not make them valid. If you add DOCTYPE declarations to your Web pages without designing them according to that standard, your Web pages may not validate and may render differently than expected or desired. Therefore, when you use a DOCTYPE declaration, you should ensure that you understand the specifications behind the HTML version and DTD.

For example, one DTD may require that all formatting is contained in cascading style sheets, while another DTD may allow formatting elements by setting attributes. To illustrate, the XHTML strict DTD does not permit setting the valign attribute but instead requires that you set a style sheet property to specify vertical alignment for an element. Conversely, the HTML 4.01 Transitional DTD allows using both the attribute and cascading style sheets to affect the appearance of an element.

However, you do not need to read every HTML specification and DTD to determine which DOCTYPE declaration to use. Instead, consider your audience. Who looks at your Web site, and which browsers do they use? If you know that visitors to your site all have the most recent browsers (for example, Internet Explorer 5.5 and later), you can use one of the HTML 4.01 or XHTML 1.0 DOCTYPE declarations and code your HTML pages to the corresponding DTD. If some of your users have earlier browsers, you may need to use an earlier HTML version, such as HTML 3.2.

Understanding your audience is a first step in determining which DOCTYPE declaration to use in your Web pages. After you determine which DOCTYPE declaration to use, you should consider using either the W3C Markup Validation Service or another HTML validator to ensure that your pages adhere to the DOCTYPE that you have declared in your pages. The validator marks anything that does not adhere to the specified DTD for the DOCTYPE, helping you learn which HTML elements and attributes are valid for the specified DOCTYPE and which are not.

List of HTML DOCTYPE Declarations

There are three major versions of HTML: HTML 4.01, HTML 3.2, and HTML 2.0. Each version has a subset of DTDs that apply to the version. The HTML versions are described in the following sections along with the valid DOCTYPE declarations for each version. For a complete list of W3C DTDs, see the List of valid DTDs you can use in your document on the W3C Web site.

Note   The HTML specification and DOCTYPE declaration descriptions in the following sections are adapted from reference documents on the W3C Web site.

HTML 4.01

HTML 4.01 is a revision of HTML 4.0 and replaces the HTML 4.0 specification. The revision fixes minor errors that were found since the release of the HTML 4.0 specification. HTML 4.01 contains the elements and attributes from earlier HTML versions, and also supports multimedia, scripting, and cascading style sheets and improves accessibility for users with disabilities. For more information, see the HTML 4.01 specification.

HTML 4.01 DTD and DOCTYPE Declarations

The W3C provides the following DTDs for HTML 4.01:

  • HTML 4.01 Strict

    The HTML 4.01 Strict DTD includes all elements and attributes that have not been deprecated or do not appear in frameset documents. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    
  • HTML 4.01 Transitional

    The HTML 4.01 Transitional DTD includes everything in the strict DTD plus deprecated elements and attributes. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
  • HTML 4.01 Frameset

    The HTML 4.01 Frameset DTD includes everything in the transitional DTD plus elements and attributes for creating frames. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
       "http://www.w3.org/TR/html4/frameset.dtd">
    

HTML 3.2

HTML 3.2 is the first HTML specification that the W3C developed; it includes support for features such as tables, applets, text flow around images, superscripts, and subscripts, while providing backward compatibility with the existing HTML 2.0 standard. For more information, see the HTML 3.2 specification.

  • HTML 3.2 DOCTYPE Declaration

    The only DOCTYPE declaration for HTML 3.2 is shown in the following example. Use this DOCTYPE declaration only if you need to validate HTML pages that may be viewed in older browsers. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    

HTML 2.0

The HTML Working Group of the Internet Engineering Task Force (IETF) developed the HTML 2.0 specification. It provided the standard for core HTML features. The W3C marks the HTML 2.0 specification as obsolete and discourages its use.

  • HTML 2.0 DOCTYPE Declaration

    The only DOCTYPE declaration for HTML 2.0 is shown in the following example. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
    

Changes in HTML Recommendations

The Internet is changing constantly and with it the languages that browsers use to render Web pages. Extensible Markup Language (XML) is quickly becoming a standard for Web pages. In an effort to make XML more accessible from within Web pages, the W3C created the XHTML specification.

Note   Similar to HTML, XML is a markup language designed for the Internet. However, unlike HTML, which was designed to define formatting of Web pages, XML was designed to describe data. Because XML is extensible, anyone can use XML to create custom elements and attributes.

XHTML 1.0

The current HTML recommendation is XHTML 1.0. XHTML 1.0 combines HTML and XML. According to the W3C, XHTML 1.0 "is a reformulation of HTML 4.01 in XML, and combines the strength of HTML 4 with the power of XML." Because XHTML 1.0 incorporates the elements and attributes HTML 4.01, browsers can render XHTML pages accurately. To transition your Web pages from earlier HTML versions, you should take a look at the HTML Compatibility Guidelines on the W3C Web site. For more information, see the XHTML 1.0 Specification.

When using XHTML 1.0, you are encouraged to preface the DOCTYPE declaration with an XML declaration. The XML declaration specifies the version of XML that the XHTML specification uses. Following is the current XML declaration for XML and XHTML documents:

<?xml version = "1.0"?>

XHTML 1.0 DTD and DOCTYPE Declarations

The W3C provides the following DTDs for XHTML 1.0:

  • XHTML 1.0 Strict

    Use the XHTML 1.0 Strict DOCTYPE declaration when you want clean markup that relies on cascading style sheets to define layout and formatting. Use the following DOCTYPE declaration when you want to use strict XHTML code. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
  • XHTML 1.0 Transitional

    The transitional DTD for XHTML 1.0 allows you to take advantage of the cascading style sheets features in XHTML but also make small changes to the HTML for formatting and layout. For example, you may use bgcolor, text, and link attributes with the BODY element, which is not allowed when using the strict DTD. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
  • XHTML 1.0 Frameset

    Use the XHTML 1.0 Frameset DTD when you want to use XHTML and your page contains one or more FRAMESET elements. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
       SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
    

XHTML 1.1

The XHTML 1.1 specification is a reformulation of XHTML 1.0 Strict that modularizes elements and attributes into convenient collections that you can use in documents that combine XHTML with content and services such as vector graphics, multimedia, math, electronic commerce, and more. It is the third recommendation for XHTML specifications. For more information, see XHTML 1.1 - Module-based XHTML and Modularization of XHTML.

  • XHTML 1.0 DTD and DOCTYPE Declaration

    The W3C provides one DTD for XHTML 1.1. For documents that use this DTD, use the following DOCTYPE declaration:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
    

Using DOCTYPE Declarations in FrontPage

As with most modern Web development tools, FrontPage may use design-time proprietary code and attributes for HTML tags that does not validate according to the standards of the W3C. If you use any design-time tools in FrontPage, your pages may not validate when submitted to a validator.

If you want to use DOCTYPE declarations in your FrontPage Web pages, you should either avoid using FrontPage design-time tools that insert custom markup or use the Optimize HTML feature (Tools menu) in FrontPage to remove most or all FrontPage design-time markup. This allows you to run the pages through a validator without receiving errors on FrontPage markup code.

For this reason, FrontPage does not include DOCTYPE declarations in new pages by default. You can add DOCTYPE declarations to your Web pages in three ways: You can paste the DOCTYPE declaration in Code view; you can insert a code snippet; or you can modify the default template that FrontPage uses to create new pages.

Entering DOCTYPE Declarations Using a Code Snippet

FrontPage includes code snippets for three DOCTYPE declarations: HTML 2.0, HTML 3.2, and HTML 4.01 Transitional. However, you should note that the code snippet for the HTML 4.01 Transitional DOCTYPE declaration does not include the URL to the DTD, which is important, as noted earlier, if you do not want the browser to render your Web page in a backward-compatible mode. Therefore, you need to modify the HTML 4.01 Transitional DOCTYPE code snippet to include a DTD reference for it to be valid. For information on working with code snippets in FrontPage, see the following FrontPage help resources on Office Online:

Modifying the FrontPage 2003 Default Template

FrontPage bases every new Web page that you create on a default template. This default template, called Normal.htm, is located at %ProgramFiles%\Microsoft Office\Templates\1033\Pages11\normal.tem\normal.htm. You can change the default HTML by opening this file in FrontPage and editing it as you would any other Web page.

To modify the Normal.htm template

  1. Open the Normal.htm file.
  2. Place the cursor before the HTML tag, and copy and paste the DOCTYPE that you want to use from the previous list.
  3. On the File menu, click Save.

Note   In two situations, FrontPage 2003 does not create Web pages using the template. One, when you create a new Web site that contains a home page (either index.htm or default.htm), FrontPage does not use the Normal.htm template for that page. Two, when you use any of the FrontPage 2003 wizards that you can use to create a new Web site, the wizards do not use the Normal.htm template when creating pages for the Web site. However, when you add new pages to an existing Web site, FrontPage uses the default template to create these pages. For additional information, see How do I declare a default DOCTYPE in my new web pages?

Resources

For more information on why you may want to use a DOCTYPE, see the following resources:

In addition to these resources, you can find many more on the Internet. Just perform an Internet search on "DOCTYPE" and search through the returned results.

Conclusion

Although there may be many reasons why you may not want to use a DOCTYPE declaration, there are just as many reasons, and more, why you should use a DOCTYPE declaration. Understanding what a DOCTYPE is and the purposes for the various DOCTYPEs takes you one step closer to developing Web sites that display the same in all browsers.