返回列表

doctype & Quirks Mode(full)

默认分类 2014/11/02 07:36

原文地址: http://en.wikipedia.org/wiki/Quirks_mode

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/strict.dtd">

The following DOCTYPE is syntactically invalid, containing the public identifier keyword "PUBLIC" but no public identifier (indicating the name of the version of HTML in use), and no system identifier URL of an HTML Document Type Definition. This 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 only in IE 6.

Quirks mode in any version of IE will also be triggered if anything precedes the DOCTYPE. For example, if a hypertext document contains a comment, space or any tag before the DOCTYPE declaration, IE will use quirks mode:

<!-- This comment will put IE 6, 7, 8, and 9 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.[6] However, for maximum compatibility with existing and older web browsers, the World Wide Web Consortium, which maintains the XHTML specification, suggests that authors of XHTML documents could consider omitting the XML declaration.[7]

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. This table applies to content served with the Content-Type text/html. Content served with the Content-Type application/xhtml+xml is rendered in Standards mode in Chrome, Firefox, Internet Explorer 9, Safari, and Opera. Internet Explorer 6, 7, and 8 do not support Content-Type application/xhtml+xml.[2]

Doctype NS6 Mozilla0.9.5-1.0 IE 8+
Firefox
Chrome
Safari
Opera 7.5+
Netscape 7+
Mozilla 1.0.1+
Konq 3.5+
HTML5 spec
IE 7
Opera 7.10
IE 6
Opera 7.0
Mac IE 5 Konq 3.2
None Q Q Q Q Q Q Q
HTML 2
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> Q Q Q Q Q Q Q
HTML 3
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN//"> 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
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 A A A
without system identifier
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
S S S A A Q A
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 A A A Q
without system identifier
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Q Q Q Q Q Q Q
HTML5
<!DOCTYPE html> Q S S A A A ?
XHTML Basic
with system identifier and without XML declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
S S S A 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 A Q A Q
with system identifier and without an 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 A A A
without system identifier and without an XML declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
S S S A A A ?
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 A Q A Q
with system identifier and without an 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 A A A Q
without system identifier and without an XML declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
S S A A A A ?
XHTML 1.1
with system identifier and an XML declaration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
S S S A Q A Q
with system identifier and without XML declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
S S S A A A A
Doctype NS6 Mozilla0.9.5-1.0 IE 8+
Firefox
Chrome
Safari
Opera 7.5+
Netscape 7+
Mozilla 1.0.1+
Konq 3.5+
HTML5 spec
IE 7
Opera 7.10
IE 6
Opera 7.0
Mac IE 5 Konq 3.2