A DTD defines the structure of an XML document through element declarations that specify element types and attributes. It allows for uniformity across XML documents through constraints like requiring certain child elements. A DTD can be internal, embedded within the XML code, or external, stored separately in its own file. It uses markup declarations like <!ELEMENT> to define tags and their hierarchical tree structures.