Web Start Letter - Website Tips and Info by Email Your Email:
We will never sell or give away your email address.

Internet Basics
   About the Internet
   About Web Browsers
   Why Domain Names

Getting Started
   Making Webpage Files
   Naming Webpage Files

Images and Colors
   How to Add Images
   Sources of Images
   Image File Formats
   Optimizing Images
   Color in HTML & CSS
   "Web-safe" Color Chart

More Advanced HTML
   Making Tables
   Formatting with Tables
   Making Forms
   Using Imagemaps
   Using Frames
   Meta Tags

Cascading Style Sheets
   Intro to CSS
   Ways to include CSS
   Some Useful CSS
   CSS Hover for Links

   Promoting Your Site
   How-To's Homepage


How to Use !DOCTYPE tag

The tag that declares a page to be XHTML is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Strictly speaking a page is NOT an XHTML page unless an XHTML !DOCTYPE tag is the first line in the file.

The tag given above is the Transitional version. Using this tag lets you use some of the older HTML features that have been superceded by XHTML and CSS if you need them for backwards compatibility.

If your page has only clean XHTML coding you can use the Strict !DOCTYPE tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

!DOCTYPE tags are case sensitive. Copy them exactly as specified.

What is a !DOCTYPE tag for

The purpose of !DOCTYPE tags is to let browsers and HTML validators know what type of document this is and to treat it accordingly.

This is an idea that comes from eXtensible Markup Language (XML). XML is a set of rules for defining markup languages that use <tags>. HTML is an XML-like markup, but not as strict. XHTML is a proper XML version of HTML.

Each XML language has a Document Type Definition (DTD). A DTD is a computer file containing the definitions of all the tags and how they can be used.

The !DOCTYPE tag tells where this .dtd file is, by including its URL. http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd for the transitional one. To learn to read and write DTDs - read about XML or take an XML class.

HTML also can use !DOCTYPE tags, though they aren't generally required. For example the !DOCTYPE tag for HTML 4.0 transitional is
<!DOCTYPE html PUBLIC "-//WEC//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Unless you tell them to expect something else, web browsers do expect your page to be HTML. So HTML and XHTML web pages without !DOCTYPE tags will still work. In order to validate your code - that is let a program check it for errors - you will need to specify a doctype.

The newest browsers (version 6+ of Netscape and IE) read doctypes and parse documents differently depending on the doctype. If you use a full doctype with URL they will sometimes be stricter than expected.

Older browsers just ignore DTDs.

This doctype switch table by Matthias Gutfeldt shows how the browsers that understand doctypes respond to the various doctype declarations. He also explains a bit about why the browser makers did it this way. He has links to more doctype info in that article also.