What is the use of DTDs in HTML?
To clarify, on the Gumbo question, Document Type Definition describes the grammar of a document type. This is practically used in document Document Declaration in document. The latter is described below.
It serves two purposes:
-
This ensures that your data is correctly described, so the document parser can know the semantics of the tags and entities that you used in the document structure.
-
In modern browsers, it triggers render modes. Most modern doctrines run "standards mode" (which is intended to comply with current or proposed web standards) or "near standard mode" (which is identical to "standard modes", except that the
display
default style is for the element<img>
block
, notinline
), in while old doctrines or no doctype will call "quirks mode" (which is rendered according to the older window model where dimensions are calculated differently, in thiswidth
element window model , for example, this is the total width of the displayed element, and its content area decreases bypadding
).
Notes:
-
I don't think any version of IE supports "near standard mode" but is easily reproduced with this line in CSS:
img { display: block; }
-
It is possible to run "quirks mode" even with the "standard mode" doctrine present if there are spaces before the doctype or in IE6 if there is an XML prologue (eg.
<?xml version="1.0" encoding="UTF-8"?>
) Before it.
a source to share
DTD is a document type definition. The DTD defines the structure as well as the legal elements and attributes of an XML document. Here's an example:
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note(to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from(#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
a source to share