DOCTYPE details _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
Tags w3c validator
We declare DOCTYPE in HTML in the following types: & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www. w3.orgTRxhtml1DTDxhtml1-transitional. dtd & quot; & gt; & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0Stric we declare in HTML that DOCTYPE generally has the following types:




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 declaration of the document as XHTML and HTML is not directly related to the document's Parse (that is, the browser's analysis of the document. 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 browser history. documents earlier than IE7 (including IE7) cannot support this format, if IE7 encounters a document in this format, it will prompt you to save it as another file. 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 is in Strict Mode (or Standard Mode. Many browsers also include Almost Standard Mode, which is not distinguished here) method 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: With the development of time, browsers will 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.