Use the Right Doctype
Pages: 1, 2
How Does It Work?
It's quite simple. If you want a document to be interpreted in "strict" mode, you have to do two things:
- Insert a DOCTYPE which claims a strict DTD in your document, or a transitional DTD with a URL pointing to that DTD.
- Make sure your document is well-formed and valid.
That's all. The second is really a follow-on to the first, but it's important. If you do claim that the document uses a strict DTD, you need to make sure that it follows that DTD. If it doesn't, the page could get very badly mangled, or possibly even refuse to display at all, and it will be your fault.
If you aren't interested in having your HTML documents held to such a standard, then you can do one of two of things:
- Don't use a DOCTYPE at all.
- Declare use of a transitional DTD, but don't include a URL.
The second case is useful if you want to validate your documents, but don't want them to be strictly standards-compliant. The first is useful if you're just slamming out pages which you aren't going to bother validating, and don't want to be strictly interpreted.
How About Some Examples?
Here are a few situations, and the effects they'll have in MacIE5:
|MacIE5 will go into "strict" mode.|
|MacIE5 will go into "strict" mode, thanks to the URL. However, authors are encouraged to avoid this behavior, since it's entirely possible that some day transitional documents will be classified as quirky instead of strict.|
|MacIE5 will go into "quirky" mode.|
|MacIE5 will go into "quirky" mode. Any HTML DTD before version 4 will trigger "quirky" mode.|
|MacIE5 will go into "quirky" mode for HTML documents.|
Note that last point there. By default, HTML documents are taken to be quirky, unless one of the "strict" triggers is found. XML documents, on the other hand, are treated as strict by default.
So What's the Difference?
Besides the simple difference that strict documents will be treated differently, strict documents will have two big differences from quirky ones. First is that all elements will inherit styles, including table elements, which have a hard time inheriting text colors and styles in quirky mode. Second is that
font-size: medium text will be the same size as unstyled text. In quirky mode, unstyled text is the same size as
There may be other differences, but they are not likely to be documented. Why not? Because as we move forward, authors should stop relying on bugwards behavior. The safety net is still there, but it won't be there forever.
Thanks to the efforts of the MacIE team at Microsoft, authors now have a way to break free of bugwards authoring, and the chance to start using standards without fearing for their older documents' appearance. And lest you fear that this will be another point of incompatibility, the team at Netscape has plans to offer this same mechanism in Netscape 6. With these two browser titans offering authors the same escape route, we may finally see standards get the kick-start they need.
Discuss this article in the O'Reilly Network Browsers forum.
Return to the O'Reilly Network Hub.