Friday, June 12, 2009

Quirks mode and strict mode

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 (Internet Explorer version 5.0 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 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 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

Quirks mode and strict mode are the two ’modes’ modern browsers can use to interpret your CSS.When Netscape 4 and IE 4 implemented CSS, their support did not match the W3C standard. Any websites rendered correctly in the various browsers, web developers had to implement CSS according to the wishes of these browsers. most websites used CSS in ways that didn’t quite match the specifications. when standards compliancy became important browser vendors faced a tough choice. Moving closer to the W3C specifications was the way to go, but if they would just change the CSS implementations to match the standards perfectly, many websites would break to a greater or lesser extent.

How to trigger quirks mode
Some doctypes or the inclusion of an declaration, trigger “quirks mode” or backwards compatible mode in IE 6. In that case, IE 6 acts like IE 5.5, and shares the same bugs, problems and behaviour as its elder brother.
In IE 7, an declaration no longer changes the rendering mode . Authors who want to keep all versions of IE up to IE 7 in quirks mode (without affecting other browsers) cannot rely on this anymore. However, inserting a comment before the doctype (but after the declaration) will still trigger quirks mode in IE 7, as in the example below.
1.
2.
3.
Quirks mode in IE 7 can also be triggered when coding HTML 4.01 documents. Inserting a comment before the DTD will trigger this backwards compatible mode in both IE 6 and IE 7.
1.
2.