Or, When a Document Type Declaration is not a DTD
Web Applications 1.0 HTML5 offers a simple Document Type Declaration for triggering standards-complaint mode.
Elegance in simplicity.
The following article constructs an explanation of how this sleight-of-hand’s achieved.
HTML 4.01 Specification, 7 The global structure of an HTML document, 7.2 HTML version information
A valid HTML document declares what version of HTML is used in the document. The document type declaration names the document type definition (DTD) in use for the document (see [ISO8879]).
HTML 4.01 specifies three DTDs, so authors must include one of the following document type declarations in their documents. The DTDs vary in the elements they support.
- The HTML 4.01 Strict DTDs includes all elements and attributes that have not been deprecated or do not appear in frameset documents. For documents that use this DTDs, use this document type declaration:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The above example is a Document Type Declaration with an attached Document Type Definition. Translated, it’s this.
!DOCTYPE HTML PUBLIC
- This is the actual Document Type Declaration.
The two following lines are the definition elements of the declaration.
"-//W3C//DTD HTML 4.01//EN"
The binding between public identifiers and files can be specified using a catalog file following the format recommended by the Oasis Open Consortium (see [OASISOPEN]). A sample catalog file for HTML 4.01 is included at the beginning of the section on SGML reference information for HTML. The last two letters of the declaration indicate the language of the DTD. For HTML, this is always English ("EN").
The URI in each document type declaration allows user agents to download the DTD and any entity sets that are needed.
The above is a simplified deconstruction. MSDN Library Web Development
!DOCTYPE offers greater detail. However, for this article, it is the table which is of interest.
“You can use this declaration to switch Microsoft Internet Explorer 6 and later into strict standards-compliant mode. You turn the switch on by including the
!DOCTYPEdeclaration at the top of your document, specifying a valid Label in the declaration, and in some cases, specifying the Definition and/or URL. The following table shows when standards-compliance is on or off.”
DOCTYPE URL Present URL Not Present No DOCTYPE present off off HTML (no version) off off HTML 2.0 off off HTML 3.0 off off HTML 4.0 on on HTML 4.0 Frameset on off HTML 4.0 Transitional on off HTML 4.0 Strict on on XHTML on on XML on on Unrecognized DOCTYPE on on
It’s that final entry —Unrecognized DOCTYPE.
MSDN Library CSS Enhancements in Internet Explorer 6 offers an explicit statement,
“To allow for the creation of new DTDs, such as HiDad 11.22, standards-compliant mode is switched on when the
!DOCTYPEdeclaration is not recognized. [Elementary emphasis.] Standards-compliant mode is also switched on when you specify a version of HTML that is not listed in the table, such as HTML 1.0 or HTML 3.22.”
From the above table, “On” translates as “pages will be rendered in standards-compliant mode” and “Off” translates as “quirks mode” (or, as MS prefers, “Compatibility Mode”).
[Note: Peter-Paul Koch offers a straightforward and concise explanation of the differences.]
<!DOCTYPE html> which is not recognized, has and will continue to trigger standards-compliant mode.