ArticleDirectory
- HTML 4.01 strict, transitional, frameset
- XHTML 1.0 strict, transitional, frameset
- XHTML 1.1 DTD
Fix your site with the right doctype! By Jeffrey zeldman
- Published in: CSS, HTML and XHTML, layout, XML|
Discuss This Article»
You 've done all the right stuff, but your site doesn' t look or work as it shoshould in the latest browsers.
You 've written valid XHTML and CSS. you 've used the W3C standard Document Object Model (DOM) to manipulate dynamic page elements. yet, in browsers designed to support these very standards, your site is failing. A faulty doctype is likely to blame.
This little article will provide you with doctypes that work, and explain the practical, real-world effect of these seemingly abstract tags.
Why a doctype?
Per HTML and XHTML standards, a doctype (short for "document type declaration") informs the validator which version of (x) HTML you're using, and must appear at the very top of every web page. doctypes are a key component of compliant Web pages: Your markup and CSS won't validate without them.
As mentioned in previous Ala articles (and in other interesting places), doctypes are also essential to the proper rendering and functioning of Web documents in compliant browsers like Mozilla, ie5/MAC, and IE6/win.
A recent doctype that includes des a full uri (a complete Web address) tells these browsers to render your page in standards-compliant mode, treating your (x) HTML, CSS, and Dom as you need CT them to be treated.
Using an incomplete or outdated doctype-or no doctype at all-throws these same browsers into "quirks" mode, where the browser assumes you 've written old-fashioned, invalid markup and code per the depressing industry norms of the late 1990 s.
In this setting, the browser will attempt to parse your page in backward-compatible fashion, rendering your CSS as it might have looked in ie4, and reverting to a proprietary, browser-specific Dom. (ie reverts to the IE Dom; Mozilla and Netscape 6 revert to who knows what .)
Clearly, this is not what you want. But it is often what you'll get, due to the preponderance of incorrect or incomplete doctype information this article hopes to correct.
(Note: The Opera browser does not play by these rules; it always attempts to render pages in standards-compliant mode. Go, opera! On the other hand, opera does not yet offer solid support for the W3C Dom. but they're working on it .) {ed: since this article was first published, opera has delivered the dom-compliant opera 7 browser .}
Where have all the doctypes gone?
Since doctypes are vital to the proper functioning of web standards in browsers, and since W3C is a leading creator of web standards, you might failed CT W3C's website to provide a listing of proper doctypes, and you might also keep CT to be able to find this information quickly and easily in a single location. but as of this writing, you can't. {ed. prompted in part by this article, the W3C now lists Standard doctypes on its site. You will find the listing a few screens into the W3C tutorial, "my Web site is standard. And yours ?"}
W3.org is not a list apart, webreference, or webmonkey. it's not intended to help web designers, developers, and content folks get up to speed on the latest technical ical recommendations and practices. that's not its job.
W3CDoesPublish a series of tutorials, though most web developers are unaware of it. Mainly, though, W3C's site houses a collection of proposals, drafts, and recommendations, writtenByGeeksForGeeks. and when I say geeks, I don't mean ordinary web professionals like you and me. I mean geeks who make the rest of us look like grandma on the first day she's got mail.
You can search for doctypes all day at w3.org without finding one page that lists them all. And when youDoHunt down a doctype (generally in relation to a particle recommendation or working draft), it's often one that won't work on your site.
Scattered throughout W3C's site are doctypes with missing Uris, and doctypesRelativeUris that point to documents ents on W3C's own site. once removed from W3C's site and used on your web pages, these Uris point to non-existent documents, thus fouling up your best efforts and the browser's.
For instance, many sites sport this doctype, copied and pasted directly from w3.org:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "DTD/xhtml1-strict.dtd">
If you look at the last part of the doctype ("DTD/xhtml1-strict.dtd"), you'll see that it is a relative link to a document on W3C's site. since that document is on W3C's site but not yours, the URI is useless to the browser.
The doctype you 'd actually want to use is:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Notice that the latter doctype between des a complete URI at the end of the tag. since the TAG provides a valid location on the Web, the browser knows where to find it, and will render your document in standards-compliant mode.
Doctypes that work
So what doctypes shocould we use? Gglad you asked. The following complete doctypes are the ones we need:
HTML 4.01 strict, transitional, frameset
<! Doctype HTML public "-// W3C // dtd html 4.01 // en" "http://www.w3.org/TR/html4/strict.dtd"> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <! Doctype HTML public "-// W3C // dtd html 4.01 frameset // en" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.0 strict, transitional, frameset
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 frameset // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1 DTD
<! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Next steps
How can you help improve support for standards on the web? Besides bookmarking this page (and copying and pasting these doctypes for your own use), if your Web Editor inserts doctypes, you might want to check them out and compare them to the list above.
Too well-intentioned software makers have cut and pasted incomplete doctypes from W3C into their software. result: when you use these programs 'Built-in functionality to insert doctypes in your pages, the browsers go into quirks mode, undoing all your hard work.
It's worth contacting the folks who make your favorite authoring package, showing them the proper doctypes, and politely requesting them to address this issue in an incremental upgrade. (in some cases, you may also be able to modify your editor yourself .)
Coming soon
We have every reason to believe that W3C's site will soon sport a handy listing of accurate, usable doctypes and other essential information in an easy-to-find location. in fact, Karl dubost, conformance manager of W3C's Quality Assurance Team, contributed to the information in this little article.
Likewise, when the web standards project relaunches (real soon), it will also provide this information. {ed. Note: The Web Standards project relaunched in late 2002 .}
But sites are being designed and built every day, and you need this information now-so there it is.
Happy authoring and rendering!
-
Translations
-
Italian (gdesign. it)
-
Bulgarian (groove manifesto)
-
French (pompage.net)
-
German (puredesign. ch)
-
Spanish (gen7es.net)
-
Russian (webmascon.com)
Learn more
Related Topics: CSS, HTML and XHTML, layout, XML
From http://www.alistapart.com/articles/doctype