[thelist] Always use a DOCTYPE (was: Horizontal scrollbar inIE 6.0)

MRC webmaster at equilon-mrc.com
Mon Feb 25 11:13:01 CST 2002


Mark,

> Removing either the DOCTYPE (or the link to the DOCTYPE) means that the
> browser has no set of "rules" to adhere to when rendering the page. This
> results in the browser "guessing" what to do with the file it's receiving
> and so it should come as no surprise when future browsers render the page
as
> plain text (not HTML) or nothing at all. It would be the same as someone
> trying to read a book in a foreign language without knowing how to
"access"
> the rules for that language - a "best guess" would be all that can be
> achieved.

    For HTML documents, removing the URI for the doctype is perfectly valid,
e.g.:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    In point of fact, few if any browsers actually rely on the dtd specified
in the doctype in order to render a page. Instead, they rely on their own
internal rules to render the page, whether in spec-compliance mode or in a
so-called "quirks" mode. In most cases, doctype-switching browsers simply
use the _presence_ of the doctype declaration and/or accompanying URI (or a
particular URI) -- or lack thereof -- to determine which method to use (and
how they do this varies from browser make to browser make [1]).
    As one example of this, you can use a perfectly valid HTML 4.01 URI in
your doctype declaration, but Mozilla/Netscape 6 will still resort to quirks
mode because it is not the particular URI that it expects:

This puts Mozilla/Netscape 6 into quirks mode:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

But this one puts it into spec-compliance mode:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    And, if you want a real-world example of a doctype declaration _without_
a URI, go to W3C's HTML 4.01 Specification [2] and view source.

> Some of the "workarounds" currently in circulation are temporary fixes and
> can only be used if you forget about the implications for future browsers
> (much the same as using

    Often true. But as the specs are not always crystal clear, different
browser makers interpret some sections differently. And unfortunately, as
each browser's spec-compliance mode has quirks of its own, some workarounds
may be necessary.

> if(version>6){alert("I'm version 6")}
>
> in Javascript will collapse when version 7 comes along.)

    Agreed (except that your example actually _would_ work for a version 7
browser, and not for a version 6 browser, but I'll take that as a typo).
Version-sniffing is probably the least-desirable approach in most cases to
channel enhanced capabilities to better-able browsers.

> The better solution is to find out the reason why a display characteristic
> is occurring and then
>
> - ignore it as it's a minor and acceptable rendering bug
> - find a solution to the problem, perhaps finding an alternative means of
> laying out the page.

    Generally true, although sometimes the solution may involve switching
off the browser's spec-compliance mode while still producing a
spec-compliant document.

James Aylard

1. For information on IE 6's doctype-switching mechanism, see:
http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp#csse
nhancements_topic2 ;
   For information on Mozilla/Netscape 6's doctype-switching mechanism, see:
http://www.mozilla.org/docs/web-developer/quirks/doctypes.html

2. http://www.w3.org/TR/html401/




More information about the thelist mailing list