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:

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.

Quirks Mode

The following trigger quirks mode (this list needs to be comprehensive to ensure that pages already existing on the Web trigger quirks mode):

The following sites have been useful in preparing this list: W3C HTML Validator, HTMLHelp HTML Validator.

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.)

See Also

Original Document Information