Mozilla's DOCTYPE sniffing

Obsolete since Gecko 2 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

This page describes behavior of the old HTML parser in Firefox 3.6 and older. It has been replaced by a new HTML 5 parser in Firefox 4 and newer.

This document describes how Mozilla uses the DOCTYPE declaration to determine strict mode vs. quirks mode. The code that makes this determination is currently in DetermineParseMode() in nsParser.cpp. See bug 1312 and bug 55264 for some of the history of the mode determination. See bug 153032 for the creation of the Almost-Standards mode around Mozilla 1.0. The goals that led to choosing this behavior were the following:

Almost all existing text/html pages on the Web that need to be in quirks mode to be displayed correctly should be displayed using quirks mode. (Almost all, rather than all, to allow for the following points as well.)

Authors writing Web pages to current standards should be able to trigger strict mode.

Pages written using any public identifiers in DOCTYPE declarations that appear in the future should be displayed using strict mode.

In other words, the algorithm is the best approximation we can find for determining which pages were written after Mozilla became a known important user-agent on the Web.

Full Standards Mode

The following trigger full standards mode:

Any document sent with an XML MIME type such as text/xml, application/xml, or application/xhtml+xml (since sniffing only occurs for documents sent as text/html).

Almost Standards Mode

The following trigger almost standards mode. Almost standards mode was created after 1.0 and 1.1alpha, but before 1.0.1 and 1.1beta. Before almost standards mode was created these doctypes triggered full standards mode.

An XML declaration (pseudo-PI) without a doctype (in other words, ignore the XML declaration and use the DOCTYPE). In 1.0 and 1.1alpha and earlier (but not in 1.0.1 or 1.1beta), the presence of an XML declaration triggered full standards mode.

Note that all public identifier comparisons are case-insensitive due to the significant number of pages that use public identifiers with incorrect case. (This is technically incorrect, since the strings are case sensitive.)