Quirks mode

Quirks mode

Quirks mode refers to a technique used by some web browsers for the sake of maintaining backwards compatibility with web pages designed for older browsers, instead of strictly complying with W3C and IETF standards in standards mode.

Overview

The structure and appearance of a web page are 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.1 for the Macintosh platform, released in 2001, was the first major web browser with full support for CSS Level 1, for example). [cite web|url=http://www.w3.org/Style/CSS/#browsers|title=Cascading Style Sheets: CSS Browsers|accessdate=2007-05-27|date=2001-12-19] 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.cite web|url=http://hsivonen.iki.fi/doctype/|title=Activating the Right Layout Mode Using the Doctype Declaration|last=Sivonen|first=Henri|accessdate=2007-05-27]

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.

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. [cite web|url=http://developer.mozilla.org/en/docs/Images,_Tables,_and_Mysterious_Gaps|title=Images, Tables, and Mysterious Gaps|publisher=Mozilla Developer Center|accessdate=2007-05-27]

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. [cite web|url=http://developer.mozilla.org/en/docs/Fixing_Table_Inheritance_in_Quirks_Mode|title=Fixing Table Inheritance in Quirks Mode|publisher=Mozilla Developer Center|accessdate=2007-05-27]

Almost standards mode

Gecko-based browsers since 1.0.1 (such as Firefox), as well as Safari and Opera 7.5 (and later) and Internet Explorer 8 (and later) have a third compatibility mode known as either "almost standards mode" or "strict mode", which maintains the "traditional" vertical sizing of table cells, against the CSS2 specification..

"Almost standards" rendering mode is exactly the same as "standards" mode in all details save one: the layout of images inside table cells is handled as they are in "quirks" mode, which is fairly consistent with other 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, than "standards" mode. [cite web|url=http://developer.mozilla.org/en/docs/Gecko's_%22Almost_Standards%22_Mode|title=Gecko's "Almost Standards" Mode|publisher=Mozilla Developer Center|accessdate=2007-05-27]

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:

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

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 6, "and in later versions 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, quirks mode will be triggered in IE 6 and also in IE 7 and IE 8 beta:

Microsoft's Chris Wilson has indicated that the problem with the XML declaration would be fixed in version 7 of Internet Explorer, in which the XML prolog will simply be ignored, [cite web|url=http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx|title=The prolog, strict mode, and XHTML in IE|last=Wilson|first=Chris|accessdate=2007-05-27|date=2005-08-15] 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. It can however be forced into quirks mode by including a comment before the DOCTYPE declaration like so:

Mode verification

In most recent browsers, the Document Object Model 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'. [cite web|url=http://msdn2.microsoft.com/en-us/library/ms533687.aspx|title=compatMode Property|accessdate=2007-05-27|publisher=Microsoft Developer Network]

Additionally, in Mozilla Firefox and Opera the rendering mode in use for a given page is indicated on the 'Page info' informational box.

References

External links

* [http://www.ericmeyeroncss.com/bonus/render-mode.html Eric Meyer on CSS: Picking a Rendering Mode]
* [http://www.quirksmode.org/css/quirksmode.html Quirksmode.org: Quirks mode and strict mode]
* [http://developer.mozilla.org/en/docs/Mozilla_Quirks_Mode_Behavior Documentation for quirks mode in Mozilla-based browsers]
* [http://www.opera.com/docs/specs/doctype/ Opera Software's explanation of quirks mode in their browser]
* [http://validator.w3.org/ The W3C Markup Validation Service]
* [http://www.phpied.com/quirks-bookmarklet/ Bookmarklet that reports the mode of a document]
* [http://developer.mozilla.org/en/docs/Mozilla's_DOCTYPE_sniffing MDC explanation of Mozilla's DOCTYPE sniffing]
* [http://vesa.piittinen.name/doctype/ Testing doctype handling in browser]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Quirks Mode — Saltar a navegación, búsqueda Quirks mode hace referencia a una técnica usada por algunos navegadores para mantener la compatibilidad hacia atrás con páginas web diseñadas para navegadores más antiguos. Contenido 1 Presentación 2 Modo Quirks,… …   Wikipedia Español

  • Quirks mode —     HTML HTML и HTML5 Динамический HTML XHTML XHTML Mobile Profile и CHTML Canvas Кодировки символов …   Википедия

  • Quirks-Mode — Der Quirks Modus (von englisch „quirk“ = Eigenart, Macke) ist ein Betriebsmodus in verschiedenen Programmen, der Fehler früherer Versionen oder vergleichbarer Programme simuliert, um Kompatibilität zu gewährleisten. Inhaltsverzeichnis 1 Quirks… …   Deutsch Wikipedia

  • Compatibility mode (browser) — Compatibility mode is a feature of Internet Explorer (IE), a web browser, from version 8 onwards. IE8 Internet Explorer 8 was promoted by Microsoft as having stricter adherence to W3C described web standards than Internet Explorer 7. As a result …   Wikipedia

  • Internet Explorer 6 — on Windows XP SP3 Developer(s) …   Wikipedia

  • Internet Explorer box model bug — The Internet Explorer box model bug is one of the best known software bugsFact|There s no proof that this is a bug. It should be called non standard behavior unless a reliable and authoritative source is cited.| ()|date=August 2008 in a popular… …   Wikipedia

  • Internet Explorer 6 — Article principal : Internet Explorer. Internet Explorer 6 Développeur Microsoft …   Wikipédia en Français

  • HTML — For the use of HTML on Wikipedia, see Help:HTML in wikitext. HTML (HyperText Markup Language) Filename extension .html, .htm Internet media type text/html Type code TEXT …   Wikipedia

  • Internet Explorer — Windows Internet Explorer A component of Microsoft Windows Internet Explorer 9 in Wi …   Wikipedia

  • Document Type Declaration — A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML or XML document (for example, a webpage) with a Document Type Definition (DTD) (for example, the formal definition of a particular version of HTML). In… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”