HTML and CSS Reference
In-Depth Information
The second and, for practical purposes, most important purpose is that doctypes in-
form browsers which parsing algorithm to use to read a document. Web browsers com-
monly have three ways they can parse an HTML document:
• No-quirks (or “standards”) mode
• Quirks mode
• Limited-quirks (or “almost standards”) mode
To render documents in one mode over another, the browser depends on the presence,
absence, or value of the doctype string. This is known as doctype switching , and it was
included in browsers as a way of determining how to render a document. The assump-
tion is that if an author has included a doctype, then that author knows what he or she
is doing, and the browser tries to interpret the strict markup in a strict way (in other
words, standards mode). The absence of a doctype triggers quirks mode, which renders
the markup in old and incorrect ways; the assumption here is that if the author hasn't
included a doctype, then he or she probably is not writing standard markup, and there-
fore the markup will be treated as if it has been written in the past for buggier browsers.
Whether no-quirks or limited-quirks mode is triggered is subtler and depends on the
doctype chosen as well as the browser the document is viewed in.
Tip Do you want to convince yourself that the browser switches parsing modes
based on the presence or absence of the doctype? If you open a page in Mozilla Firefox
4 and select Tools Page Info, under the General tab you will see a Render Mode list-
ing that will show the current mode being used to view the page. If you add and remove
the doctype declaration from a web page and check the Page Info during each state, you
will see that the browser is triggering different parsing modes. Alternatively, if you are
familiar with JavaScript, insert the following script into the head section of an HTML
page:
<script type="text/javascript">
alert(document.compatMode);
</script>
Search WWH ::




Custom Search