About the Internet
About Web Browsers
Why Domain Names
HTML vs XHTML
Making Webpage Files
Naming Webpage Files
About HTML Tags
Basic HTML Page
DTDs and Doctype Tags
Spaces and New Lines
Bold, Italics, More
Comments in HTML
How to Add Images
Sources of Images
Image File Formats
Color in HTML & CSS
"Web-safe" Color Chart
Formatting with Tables
Intro to CSS
Ways to include CSS
Some Useful CSS
CSS Hover for Links
Promoting Your Site
!DOCTYPE and DTDs
How to Use !DOCTYPE tag
The tag that declares a page to be XHTML is:
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 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
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.