A Document Type Definition, or DTD, is a grammar that declares what a particular class of markup documents may contain. It lists the element types that are permitted, the content each element may hold, the attributes elements may carry, and the entities the document may reference. With a DTD in hand, a parser can check whether a given document conforms to its declared type — a process the XML specification calls validity. The DTD is therefore the original schema mechanism for markup: a separate, machine-checkable description of structure, distinct from any individual document.
The DTD concept comes directly from SGML, where defining a document type was the central act of using the language. XML inherited it and built it into the XML 1.0 Recommendation. That specification draws the key distinction between two levels of conformance: a document is well-formed if it obeys XML’s basic syntactic rules, and it is additionally valid if it has an associated DTD and conforms to the constraints expressed in it. This means a DTD is optional in XML — many XML documents are merely well-formed — but when present it lets a processor enforce a contract about structure.
Mechanically, a DTD is written in its own declarative syntax rather than in XML itself. Element declarations specify content models — for example, that a chapter element must contain a title followed by one or more paragraphs. Attribute-list declarations specify which attributes an element may have, their types, and whether they are required or carry default values. Entity declarations define reusable text or external references. The DTD can be embedded in the document’s internal subset, pulled in from an external file, or both, with rules governing how the two combine.
A DTD’s strengths are simplicity and a compact way to express content models and entity substitution, and for years it was the standard way to validate HTML and XML documents. But it has well-known limitations: a DTD is not written in XML, it has only a weak notion of data types, and it has no native support for XML namespaces, which became important once documents began mixing vocabularies. These gaps motivated richer schema languages.
The principal successor is XML Schema, whose own W3C Recommendation explicitly notes that it “substantially reconstructs and considerably extends the capabilities found in XML 1.0 document type definitions (DTDs).” XML Schema is itself written in XML, supports namespaces, and provides a full datatype system. Other alternatives such as RELAX NG followed as well. Even so, the DTD remains historically central as the mechanism that carried SGML’s idea of a declared, validatable document grammar into XML and the web.