Document Type Declaration (DOCTYPE)
The DOCTYPE (document type declaration) has caused problems for many of us, so we thought we should give DOCTYPE its own page.
According to the W3C specifications, the DOCTYPE begins the HTML or XHTML document and tells a validator which version of HTML to use in checking the document's syntax. However, as many of us have learned the hard way, using the wrong DOCTYPE or no DOCTYPE at all may cause a page to fail, particularly a page that uses CSS, JavaScript, or DHTML. This is because an incorrect DOCTYPE can cause the newer standards-compliant browsers to revert to a "quirks" mode, and they will try to parse the page in a backward-compatible fashion. The browser will try to render CSS as it might have looked in IE4 and, for JavaScripts, the browser will revert to a proprietary, browser-specific DOM (Document Object Model). In standards-compliant browsers, the correct DOCTYPE is essential for the proper rendering of HTML and XHTML, CSS, and the DOM.
The following is a description of some suggested DOCTYPES and when they should be used for the proper validation and rendering of a document.
HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Strict emphasizes structure over presentation. Deprecated elements and attributes (including most presentational attributes), frames, and link targets are not allowed in HTML 4 Strict. You need to use CSS with HTML 4 Strict but, since older browsers lack full support for style sheets, HTML 4 Strict documents may not look as the developer intended when viewed in older browsers.
HTML 4.01 Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
HTML 4 Transitional includes all elements and attributes of HTML 4 Strict but allows presentational attributes, deprecated elements, and link targets. HTML 4 Transitional recognizes the relatively poor support for style sheets in older browsers and allows many HTML presentation features to be used as a transition towards HTML 4 Strict and XHTML.
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This is the XHTML DOCTYPE that is equivalent to HTML 4.01 Strict.
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This is the XHTML DOCTYPE that is equivalent to HTML 4.01 Transitional.
The XML Declaration
Finally, here is something else that some of us have learned the hard way. The W3C XHTML specification recommends, but does not require, the addition of the following XML declaration to XHTML documents:
<?xml version="1.0" encoding="iso-8859-1"?>
However, that declaration can cause XHTML documents to fail to render correctly, so we recommend against including it in your XHTML documents at this point in time. Unfortunately, Dreamweaver MX automatically inserts the <?xml?> declaration at the top of XHTML documents. We posted to the Dreamweaver newsgroup and wrote to Dreamweaver Tech Support, but no one could tell us how to prevent Dreamweaver MX from inserting the <?xml?> declaration. We had to remember to manually delete the declaration before saving each file.
We still don't know how to prevent Dreamweaver MX from inserting the <?xml?> declaration, but Angela C. Buraglia, the founder of DreamweaverFAQ.com, has developed a free extension called Strip <?xml?> Tag that removes the <?xml?> declaration from XHTML pages and removes the PHP <?xml?> declaration from PHP documents, but does not disturb the <?xml?> declaration in .xml files. The extension works automatically every time you save a document so you never have to do a thing.
Every Dreamweaver MX user should download and install the free Strip <?xml?> Tag extension
from the DreamweaverFAQ
Store.
You must be a registered user in order to download from the DreamweaverFAQ
Store, but registration is free.