开发者

What is the use of DTD in HTML?

开发者 https://www.devze.com 2022-12-29 12:59 出处:网络
Could anyo开发者_如何学Gone specify what is the need and use of the Document Type Declaration in HTML pages. What is the advantages of it? I searched through the Net and found the results to be little

Could anyo开发者_如何学Gone specify what is the need and use of the Document Type Declaration in HTML pages. What is the advantages of it? I searched through the Net and found the results to be little bit confusing. Please someone highlight.


To clarify, per Gumbo's question, the Document Type Definition describes the grammar of a document type. This is practically applied with a Document Type Declaration in a document. The following describes the latter.

It does two things:

  1. It ensures that your data is correctly described, so a document parser can know the semantics of the tags and entities you've used in the document structure.

  2. In modern browsers, it triggers rendering modes. Most modern doctypes trigger "standards mode" (which is meant to follow current or proposed web standards) or "almost standards mode" (which is identical to "standards mode" except that the default display style for the <img> element is block rather than inline), while older doctypes or no doctype will trigger "quirks mode" (which renders according to an older box model where dimensions are calculated differently; in this box model, the width of an element, for example, is the total width of the displayed element and its content area is reduced by padding).

Notes:

  1. I don't think any version of IE supports "almost standards mode", but it's easily reproduced with this line in CSS: img { display: block; }

  2. It is possible to trigger "quirks mode" even with a "standards mode" doctype present, if there is whitespace before the doctype, or in IE6 if there is an XML prologue (eg. <?xml version="1.0" encoding="UTF-8"?>) before it.

0

精彩评论

暂无评论...
验证码 换一张
取 消