Detailed introduction to DOCTYPE types_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:45:51
Original
1166 people have browsed it

When we declare DOCTYPE in HTML, we generally have the following types:




Yes, there are HTML and XHTML, as well as Transitional and Strict. As the name suggests, XHTML means that the document is written in XML format, while HTML means that the document is written in HTML format. Transition means that the document meets the requirements of Transitional.dtd or loose.dtd, and Strict means that the document meets the requirements of strict.dtd. But in fact we often have the following misunderstandings:
(1) If my document is declared as XHTML, then my document must be in full XML format.
(2) If my document is declared as Strict, then my document must be rendered in Strict Mode. Otherwise, it will be rendered in Quirks Mode.
These two understandings are very straightforward, but they are wrong. We often make this mistake.
First of all, the document declaration is XHTML and HTML, which is not directly related to the Parse of the document (that is, the browser's analysis of the document). In fact, how the browser parses the document depends on the format in which the server provides the document. Normally, there are two ways, "text/html" and "application/xhtml xml". Only documents provided in the "application/html xml" format can be parsed in XML format. However, due to browser history, not all browsers support "application/xhtml xml" format documents. Versions before IE7 (including IE7) cannot support this format. If IE7 encounters this format document, it will prompt the user to save as another file. Considering the widespread use of IE, most documents are currently provided in the form of "text/html". Documents provided in the "text/html" format are parsed according to the semantics of HTML. Everyone knows that HTML is very fault-tolerant. Even if the TAG in your document is not closed correctly, the HTML can still be parsed correctly. land is displayed. Therefore, if your XHTML is provided in the form of "text/html" (in most cases), then even if you declare XHTML in the DOCTYPE, your document will not be parsed in XML format. Therefore, there is no guarantee that your document strictly follows XML specifications. In fact, many experts recommend that if your document is not provided as "application/xhtml xml", then you should declare it as HTML.
Secondly, the way in which the browser renders your document is not determined by the DTD you declare. In fact, if you declare DOCTYPE and DTD, your document will be rendered in Strict Mode (or Standard Mode, many browsers also include Almost Standard Mode, no distinction will be made here). For documents without DOCTYPE, they are rendered in Quirks Mode. Therefore, the browser's Render mode has no direct relationship with the DTD you declare.
Finally, there is no difference in current browsers whether you declare it as Strict.dtd or Transitional.dtd. Strict.dtd is much stricter than Transitional.dtd or loose.dtd. Many elements cannot be used in strict.dtd. However, due to browser compatibility, even if you declare Strict.dtd in DOCTYPE, if the browser encounters elements that are not allowed in strict.dtd, it will still be able to display your document correctly. My guess is that the browser doesn't take the DTD into account. For example, the TAG iframe does not exist in strict.dtd, but even if strict.dtd is declared in your DOCTYPE and then the TAG iframe is used, browsers (including IE7, IE8, FF3.0, Safari 3.0) will be able to correctly display your document. The browser does not parse your document according to the DTD you declared. Currently, you can guarantee whether your document conforms to strict.dtd or Transitional.dtd. It can only be analyzed through some online validators, such as W3C Validator. The browser does not give you good support. Of course, in fact, it would be best if you could write your document strictly according to the DTD you declared. This will ensure that your document will not produce errors when the browser strictly abides by the DTD in the future.
Therefore,
(1) If your document is provided as "text/html", then you should declare it as HTML. This is especially true if you want IE7 to display correctly.
(2) If your document is declared as XHTML, then you should provide it in the form of "application/html xml".
(3) Try to declare DOCTYPE and DTD in front of your document to ensure that you are not rendering the document in Quirks Mode.
(4) If you declare a DTD, then you must write your document strictly in accordance with the requirements of the DTD. Especially if you declare Strict.dtd, you should pay attention to which elements cannot be used.
Note: Over time, browser support for HTML and XHTML, Strict.dtd and Transitional.dtd will get better. If your browser is much higher than IE7, IE8, FF 3.0 and Safari 3.0, then you should pay attention to the applicability of this article.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!