Opentopia Directory Encyclopedia Tools

Quirks mode

Encyclopedia : Q : QU : QUI : Quirks mode


Quirks mode refers to a technique used by some web browsers to maintain backwards compatibility with web pages designed for older browsers.

Overview

Web pages are produced using two languages: HTML, a markup language designed for web use, describes the structure and content of a page, and Cascading Style Sheets (CSS), a generalized stylesheet language, 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, the implementations of these languages in web browsers, particularly implementations of CSS, were at first minimal and known to contain many bugs or "quirks". Compounding this problem, many web page authors did not refer to the existing specifications for these languages to find workarounds, and instead used the (incorrect) renderings of then-current web browsers as a baseline of "correct" behavior.

The result is that, although browser support for standards-conformant rendering of HTML and CSS has improved dramatically, there exist a large number of web pages which assume the existence of older browsers' bugs and will not render in a standards-conformant browser as the author intended. These typically fall into two broad categories: "legacy" pages that pre-date the common use of web standards – many of which are no longer maintained by their authors – and newer pages that are created by authors who are unaware of web standards, as an understanding of them is not required to produce a working web page.

Quirks mode, standards mode, and almost-standards mode

To work around this problem and maintain compatibility with the greatest possible number of web pages, web browser developers generally design their software to use either of two 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, in order to ensure that these pages render as their authors intended. Some browsers (those based on Mozilla's Gecko rendering engine, for example), also use an "almost standards" mode which attempts to compromise between the two, emulating some older quirks while mostly conforming with the specifications.

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:

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:

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 declaration, 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:

Microsoft's Chris Wilson has indicated that the problem with the XML declaration will be fixed in version 7 of Internet Explorer, in which the XML prolog will simply be ignored [link], but 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.

Internet Explorer 6 will also render HTML 4 pages with a DOCTYPE in quirks mode if a URL for the DTD is not provided.

In addition some browsers have an "almost standards mode", which implements all but the most painful of strict mode rules [link].

Examples of differences between quirks mode and standards mode

One prominent difference between quirks and standards modes the handling of the CSS box model in Microsoft's Internet Explorer browser. 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[link]. Some developers who wish to use this behavior while remaining in standards mode use a CSS declaration to force images to display as block elements..

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-complient 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 inehrit 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[link].

Verifying which rendering mode is in use

In Mozilla Firefox, the 'Page Info' dialog box will indicate the rendering mode in use for a given page. In Internet Explorer, the JavaScript property document.compatMode indicates the rendering mode for the current page -- in standards mode, document.compatMode contains the value 'CSS1Compat', while in quirks mode it contains the value 'BackCompat'[link].

See also

External links

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: