DOCTYPE, HTML and XHTML, Strict DTD and Transitional DTD, Quirks mode and Standard mode

Source: Internet
Author: User

In the HTML declaration DOCTYPE general will have the following several:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http:// "> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://" > <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >

Yes, there are HTML and XHTML, as well as transitional and strict. As the name implies, XHTML means that the document is written in XML format, while HTML means that the document is written in HTML format. Transition said the document met the requirements of TRANSITIONAL.DTD or LOOSE.DTD, and strict said the document met STRICT.DTD requirements. But in fact we often have the following misconceptions: (1) My Documents are declared XHTML, and My Documents are definitely in the format of XML. (2) My document is declared as strict, then my document must be in accordance with the strict mode of the way to render, on the contrary, is quirks mode to render.

Both of these understandings are straightforward, but they are wrong, and we often make such mistakes.

First, the document is declared as XHTML and HTML, and the parse of the document (that is, the browser's parsing of the document) is not directly related. In fact, how the browser parse document depends on what format the server provides for this document. Typically, there are two ways of "text/html" and "Application/xhtml+xml". Only documents provided in a "application/html+xml" manner can be parse in the same way as XML. However, because of the browser's historical reasons, not all browsers support the "Application/xhtml+xml" format of the document, IE7 previous version (including IE7) will not be able to support this format, if IE7 encountered in this format of the document, it will prompt the user to save as other files. Considering the wide use of IE, most of the documents are provided in a "text/html" way. The "text/html" way to provide the document is in accordance with the semantics of HTML to parse, we all know that the fault tolerance of HTML is very strong, even if the tag in your document is not closed properly, this HTML can be correctly displayed. So if your XHTML is provided in a "text/html" way (in most cases), then even if you declare XHTML in DOCTYPE, your document is not in XML format, Therefore, there is no guarantee that your documents are strictly in accordance with the XML specification. In fact, many experts suggest that if your document is not provided in a "Application/xhtml+xml" way, you should declare it as HTML.

Second, the way the browser will render your document is not determined by the DTD you declared. In fact, if you declare the DOCTYPE and DTD, your document is strict mode (or Standard mode, many browsers also include the way almost standard mode, which is not differentiated here) to render. For documents without DOCTYPE, the quirks mode is the way to render. Therefore, the render mode of the browser does not have a direct relationship with the DTD you declare.

Finally, you declare as STRICT.DTD or TRANSITIONAL.DTD, in the current browser seems to be no different. STRICT.DTD than TRANSITIONAL.DTD or loose.dtd to be more strict, many elements in the STRICT.DTD can not be used. However, because of browser compatibility, even if you declare strict.dtd inside the DOCTYPE, the browser will be able to display your document correctly if it encounters elements that are not allowed in the STRICT.DTD. I guess the browser didn't take the DTD into account. For example IFRAME This tag does not exist inside STRICT.DTD, but even if your doctype inside declares STRICT.DTD, then uses the IFRAME this tag, browser (including Ie7,ie8,ff3.0,safari 3.0) are able to display your documents correctly. The browser did not parse your document according to the DTD you declared. At present can ensure that your documents are in line with STRICT.DTD or TRANSITIONAL.DTD, only through some online validator, such as the validator to analyze, the browser can not give you a good support. Of course, it is best if you can write your document in strict accordance with your stated DTD, so that your document does not produce errors when the browser adheres to the DTD in the future.


(1) If your document is provided in a "text/html" way, then you should declare it as HTML. If you want IE7 to be able to display correctly, then you should do so. (2) If your document is declared XHTML, you should provide it in a "application/html+xml" manner. (3) Try to declare doctype and DTDs in front of your document so that you do not render the document in quirks mode. (4) If you declare a DTD, you must write your document in strict accordance with the requirements of the DTD. Especially if you declare STRICT.DTD, you should be aware of which elements are not available.

Note: This article was released on 2008.5.20. As time progresses, browsers support HTML and XHTML,STRICT.DTD and TRANSITIONAL.DTD better. If your browser is much higher than IE7, IE8, FF 3.0 and Safari 3.0, then you should be aware of the applicability of this article.

DOCTYPE, HTML and XHTML, Strict DTD and Transitional DTD, Quirks mode and Standard mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.