What is the use of DTDs in HTML?

Can anyone please point out what is the need and use of Document Type Declaration in HTML pages. What are its advantages? I searched the web and found the results a little confusing. Please highlight someone.

+2


a source to share


3 answers


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

    , not inline

    ), 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 this width

    element window model , for example, this is the total width of the displayed element, and its content area decreases by padding

    ).



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.

+7


a source


A document type definition (DTD) is a set of markup declarations that define a document type for a markup language of the SGML family.



+4


a source


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>

      

+1


a source







All Articles