Doctype, strict DTD and transitional DTD do not conform to the theory and practice

Source: Internet
Author: User
Tags w3c validator
If not Doctype, HtmlAnd XHTML, Strict DTDAnd TransitionalDTD, Quirks ModeAnd StandardBefore reading this article, we strongly recommend that you read the DOCTYPE, HTML, XHTML, Quirks Mode, and Standard Mode WebpageWhy are the results of this article related TheoryWhat about Transitional and Strict? Please refer to the following article

We declare DOCTYPE in HTML in the following types:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<! 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 indicates that this document is written in XML format, while HTML indicates that this document is written in HTML format. Transition indicates that the document meets the requirements of Transitional. dtd or loose. dtd, and Strict indicates that the document meets the requirements of strict. dtd. But in fact, we often have the following misunderstandings:
(1) My documents are declared as XHTML, and my documents must be in XML format.
(2) My document is declared as Strict, and my document must be Render in Strict Mode. On the contrary, it is Render in Quirks Mode.

Both of them are straightforward, but they are incorrect. We often make such mistakes.

First, the document is declared as XHTML and HTML, and the document's Parse (that isBrowserIs not directly associated. In fact, the browser's Parse document depends on the format in which the server provides this document. Generally, there are two methods: "text/html" and "application/xhtml + xml ". Only documents provided in "application/html + xml" mode can be Parse in XML mode. However, not all browsers support documents in the "application/xhtml + xml" format due to the browser's historical reasons. Versions earlier than IE7 (including IE7) cannot support this format, if IE7 encounters a document in this format, it will prompt the user to save it as anotherFile. Considering the wide application of IE, most of the documents are currently provided in the form of "text/html. Documents provided in the "text/html" mode are Parse Based on the HTML semantics. We all know that HTML is highly fault tolerant, even if the TAG in your document is not properly closed, This HTML can be correctly displayed. Therefore, if your XHTML is provided in the form of "text/html" (in most cases), even if you declare XHTML in DOCTYPE, your documents are not Parse in XML format. Therefore, you cannot guarantee that your documents comply with XML standards strictly. In fact, many experts suggest that if your document is not provided in the "application/xhtml + xml" method, you should declare it as HTML.

Secondly, the way in which the browser Render your document is not determined by the DTD you declare. In fact, if you declare DOCTYPE and DTD, your document uses Strict Mode (or Standard Mode). Many browsers also includeAlmostStandard Mode, which is not distinguished here) to Render. Only documents without DOCTYPE can be Render in Quirks Mode. Therefore, the browser's Render mode is not directly related to the DTD you declare.

Finally, if you declare Strict. dtd or Transitional. dtd, there is no difference in the current browser. Strict. dtd is much stricter than Transitional. dtd or loose. dtd. Many elements cannot be used in strict. dtd. However, because of browser compatibility, even if you declare Strict. dtd in DOCTYPE, the browser can display your documents correctly even if it encounters an element not allowed in strict. dtd. I guess the browser didn't take the DTD into consideration. For example, the iframe TAG is in strict. the dtd does not exist, but even if your DOCTYPE declares strict. dtd, and then use the iframe TAG. the browser (including IE7, IE8, FF3.0, Safari 3.0) can correctly display your document. The browser does not Parse your document according to the DTD you declare. At present, you can ensure that your documents comply with strict. dtd or Transitional. dtd and can only be analyzed through some online Validator, such as W3C Validator, which cannot be well supported by browsers. Of course, if you can write your document strictly according to the DTD you declare, it is the best, which ensures that the browser will strictly abide by the DTD in the future, your document will not produce errors.

Therefore,

(1) If your document is provided in the form of "text/html", you should declare it as HTML. If you want IE7 to be correctly displayed, you should do more.
(2) If your document is declared as XHTML, you should provide it in the form of "application/html + xml.
(3) Try to declare DOCTYPE and DTD before 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 note which elements cannot be used.

Note: This article was published on 2008.5.20. With the development of time, browsers have better support for HTML and XHTML, strict. DTD and transitional. DTD. If your browser is much higher than IE7, IE8, FF 3.0 and Safari 3.0, pay attention to the applicability of this article.

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: info-contact@alibabacloud.com 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.