Quirks mode
From Wikipedia, the free encyclopedia
HTML |
---|
|
Quirks mode refers to a technique used by some web browsers for the sake of maintaining backward compatibility with web pages designed for older browsers, instead of strictly complying with W3C and IETF standards in standards mode.
Contents |
[edit] Overview
The structure and appearance of a web page is described by a combination of two standardized languages: HTML, a markup language designed for web use, which describes the structure and content of the page, and CSS, a generalized stylesheet language, which specifies how the page should be rendered in various media (visual styles for screen display, print styles to use when printing the page, aural styles to use when the page is read aloud by a screen reader, etc.). However, most older web browsers either did not fully implement the specifications for these languages or were developed prior to the finalization of the specifications (Microsoft Internet Explorer version 5.0 for the Macintosh platform, released in 2000, was the first major web browser with full support for CSS Level 1, for example).[1] As a result, many older web pages were constructed to rely upon the older browsers' incomplete or incorrect implementations, and will only render as intended when handled by such a browser.
Support for standardized HTML and CSS in major web browsers has improved significantly, but the large body of legacy documents which rely on the quirks of older browsers represents an obstacle for browser developers, who wish to improve their support for standardized HTML and CSS, but also wish to maintain backward compatibility with older, non-standardized pages. Additionally, many new web pages continue to be created in the older fashion, since the compatibility workarounds introduced by browser developers mean that an understanding of standardized methods is not strictly necessary.
To maintain compatibility with the greatest possible number of web pages, modern web browsers are generally developed with multiple rendering modes: in "standards mode" pages are rendered according to the HTML and CSS specifications, while in "quirks mode" attempts are made to emulate the behavior of older browsers. Some browsers (those based on Mozilla's Gecko rendering engine, or Internet Explorer 8 in strict mode, for example) also use an "almost standards" mode which attempts to compromise between the two, implementing one quirk for table cell sizing while otherwise conforming to the specifications.[2]
[edit] Comparison of document types
Henri Sivonen compiled a list of various document types and how they are treated in the most common browsers, showing whether pages are rendered in Quirks, Standards, or Almost standards mode. The criterion used for "Almost standards mode" is non-standard table cell height rendering.[2]
Doctype | NS6 | Gecko pre-1.0.1 | Gecko 1.0.1+ Safari Opera 9.X Konq 4.X |
Konq 3.2 | Opera 7.5 | IE 7 Opera 7.10 |
IE 6 Opera 7.0 |
IE Mac | |
---|---|---|---|---|---|---|---|---|---|
None | Q | Q | Q | Q | Q | Q | Q | Q | |
HTML 3.2 | |||||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | Q | Q | Q | Q | Q | Q | Q | Q | |
HTML 4.01 | |||||||||
Strict | with system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
S | S | S | A | S | A | A | A |
without system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> |
S | S | S | A | S | A | A | Q | |
Transitional | with system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
S | S | A | Q | A | A | A | A |
without system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
Q | Q | Q | Q | Q | Q | Q | Q | |
Frameset | with system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> |
S | S | A | ? | S[3] | A | A | S |
without system identifier <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"> |
Q | Q | Q | ? | Q[3] | Q | Q | Q | |
HTML 5 | |||||||||
<!DOCTYPE html> | Q | S | S | ? | S | A | A | A | |
XHTML Basic | |||||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> | S | S | S | A | S | A | A | A | |
XHTML 1.0 | |||||||||
Strict | with system identifier and XML declaration <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
S | S | S | Q | S | A | Q | A |
with system identifier and without a XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
S | S | S | A | S | A | A | A | |
without a system identifier and XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> |
S | S | S | ? | ? | A | A | S | |
Transitional | with system identifier and with XML declaration <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
S | S | A | Q | A | A | Q | A |
with system identifier and without a XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
S | S | A | Q | A | A | A | A | |
without a system identifier and without a XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> |
S | S | A | ? | ? | A | A | S | |
Frameset | with system identifier and without an XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> |
S | S | A | ? | ? | A | A | S |
without a system identifier and without an XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"> |
S | S | A | ? | ? | A | A | S | |
XHTML 1.1 | |||||||||
Strict | with system identifier and without an XML declaration <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
S | S | S | A | S | A | A | A |
Doctype | NS6 | Gecko pre-1.0.1 | Gecko 1.0.1+ Safari Opera 9.X Konq 4.X |
Konq 3.2 | Opera 7.5 | IE 7 Opera 7.10 |
IE 6 Opera 7.0 |
IE Mac |
[edit] Mode differences and examples
One prominent difference between quirks and standards modes is the handling of the CSS Internet Explorer box model bug. Before version 6, Internet Explorer used an algorithm for determining the width of an element's box which conflicted with the algorithm detailed in the CSS specification, and due to Internet Explorer's popularity many pages were created which relied upon this incorrect algorithm. As of version 6, Internet Explorer uses the CSS specification's algorithm when rendering in standards mode and uses the previous, non-standard algorithm when rendering in quirks mode.
Another notable difference is the vertical alignment of certain types of inline content; many older browsers aligned images to the bottom border of their containing box, although the CSS specification requires that they be aligned to the baseline of the text within the box. In standards mode, Gecko-based browsers will align to the baseline, and in quirks mode they will align to the bottom.[4]
Additionally, many older browsers did not implement inheritance of font styles within tables; as a result, font styles had to be specified once for the document as a whole, and again for the table, even though the CSS specification requires that font styling be inherited into the table. If the font sizes are specified using relative units, a standards-compliant browser would inherit the base font size, then apply the relative font size within the table: for example, a page which declared a base font size of 80% and a table font size of 80% (to ensure a size of 80% in browsers which do not properly inherit font sizes) would, in a standards-compliant browser, display tables with a font size of 64% (80% of 80%). As a result, browsers typically do not inherit font sizes into tables in quirks mode.[5]
[edit] Almost standards mode
A third compatibility mode known as either "almost standards mode" or "strict mode" which maintains the "traditional" vertical sizing of table cells according to the CSS2 specification, has been implemented in these browsers: Safari, Opera 7.5 (and later), all Gecko-based browsers since 1.0.1 (such as Firefox) and Internet Explorer 8.[2]
"Almost standards" mode rendering matches "standards" mode in all details except for one. The layout of images inside table cells is handled the same way "quirks" mode operates, instead, which is fairly consistent with legacy browsers such as Internet Explorer 6 (and earlier). This means that sliced-images-in-tables layouts are less likely to fall apart in browsers when in either "quirks" or "almost standards" mode, rather than "standards" mode.[6]
[edit] Triggering different rendering modes
Most often, browsers determine which rendering mode to use based on the presence of a Document Type Declaration in the page; if a full DOCTYPE is present the browser will use standards mode, and if it is absent the browser will use quirks mode. For example, a web page which began with the following DOCTYPE would trigger standards mode:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/DTD/strict.dtd">
While this DOCTYPE (which does not contain either the version of HTML in use, or the URL of an HTML Document Type Definition) would trigger quirks mode:
<!DOCTYPE html PUBLIC>
Additionally, a web page which does not include a DOCTYPE at all will render in quirks mode.
One notable exception to this is Microsoft's Internet Explorer 6 browser, which will render a page in quirks mode if the DOCTYPE is preceded by an XML prolog, regardless of whether a full DOCTYPE is specified. Thus an XHTML page which begins with the following code would be rendered in quirks mode by IE 6:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The above is useful to an extent as it can be used to trigger quirks mode in IE 6, but no other browsers.
Quirks mode in IE any version of IE will also be triggered if anything but whitespace precedes the DOCTYPE. For example, if a hypertext document contains a comment or any tag before the DOCTYPE, IE will use quirks mode:
<!-- This comment will put IE 6, 7 and 8 in quirks mode --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The problem with the XML declaration was fixed in version 7 of Internet Explorer, in which the XML prolog is simply ignored.[7] However, for maximum compatibility with existing and older web browsers the World Wide Web Consortium, which maintains the XHTML specification, recommends that authors of XHTML documents omit the XML declaration when possible.[8]
[edit] Mode verification
In most browsers, the Document Object Model extension document.compatMode indicates the rendering mode for the current page—in standards mode and almost-standards mode, document.compatMode contains the value "CSS1Compat", while in quirks mode it equals "BackCompat".[9]
Additionally, in Mozilla Firefox and Opera the rendering mode in use for a given page is indicated on the 'Page info' informational box.
[edit] References
- ^ "Cascading Style Sheets: CSS Browsers". 19 December 2001. http://www.w3.org/Style/CSS/#browsers. Retrieved on 27 May 2007.
- ^ a b c Sivonen, Henri. "Activating Browser Modes with Doctype". http://hsivonen.iki.fi/doctype/. Retrieved on 1 December 2008.
- ^ a b "The Opera 9 DOCTYPE switches". Opera Software. http://www.opera.com/docs/specs/doctype/. Retrieved on 14 February 2009.
- ^ "Images, Tables, and Mysterious Gaps". Mozilla Developer Center. http://developer.mozilla.org/en/docs/Images,_Tables,_and_Mysterious_Gaps. Retrieved on 27 May 2007.
- ^ "Fixing Table Inheritance in Quirks Mode". Mozilla Developer Center. http://developer.mozilla.org/en/docs/Fixing_Table_Inheritance_in_Quirks_Mode. Retrieved on 27 May 2007.
- ^ "Gecko's "Almost Standards" Mode". Mozilla Developer Center. http://developer.mozilla.org/en/docs/Gecko's_%22Almost_Standards%22_Mode. Retrieved on 27 May 2007.
- ^ Wilson, Chris (15 August 2005). "The <?xml> prolog, strict mode, and XHTML in IE". http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx. Retrieved on 27 May 2007.
- ^ "HTML Compatibility Guidelines". XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition). World Wide Web Consortium. 1 August 2002. http://www.w3.org/TR/xhtml1/#guidelines. Retrieved on 14 February 2009.
- ^ Koch, Peter-Paul (2 February 2009). "Miscellaneous". W3C DOM Compatibility - HTML. QuirksMode. http://www.quirksmode.org/dom/w3c_html.html#misc. Retrieved on 14 February 2009.
[edit] External links
- Eric Meyer on CSS: Picking a Rendering Mode
- Quirksmode.org: Quirks mode and strict mode
- Documentation for quirks mode in Mozilla-based browsers
- Opera Software's explanation of quirks mode in their browser
- The W3C Markup Validation Service
- Bookmarklet that reports the mode of a document
- MDC explanation of Mozilla's DOCTYPE sniffing
- Testing doctype handling in browser
- Joel Spolsky on Web standards