What is the DTD file format?
DTD stands for Document Type Definition. A .dtd file is a plain text file that defines the permitted elements, attributes, and structure of an XML, XHTML, HTML, or SGML document.
The data saved in a DTD file describes the structure of its associated document - including allowed nesting and ordering of elements. DTD files ensure consistency when documents are exchanged between systems; a validating XML parser can also check the validity of a specific document against its DTD. Declarations use three main types: <!ELEMENT> (child elements), <!ATTLIST> (attributes), and <!ENTITY> (reusable text macros).
DTDs originated with the SGML standard (ISO 8879, 1986) and were adopted by the W3C XML 1.0 specification in 1998. Well-known public DTDs cover XHTML, DocBook, SVG, and MathML. Because DTDs lack XML namespace support and rich data types, XSD (W3C XML Schema) and RELAX NG are now the preferred alternatives. HTML5 uses a minimal <!DOCTYPE html> declaration that does not reference an actual DTD file.
Security & safety
RISK: LOWPlain text file; no executable content. DTD external entity declarations (<!ENTITY % name SYSTEM 'url'>) can cause XML External Entity (XXE) attacks when processed by XML parsers in application code - not a risk from opening the DTD file itself, but a risk when the DTD is used in an application that parses untrusted XML with DTD processing enabled. Safe to open in a text editor.
Format details
in a nutshellPrograms that open DTD files
Technical details
deep spec| File type | Plain text schema/declaration file |
| MIME type | application/xml-dtd; text/plain (alternate) |
| Magic bytes | None - plain text (may begin with an XML comment or directly with a <!ELEMENT declaration) |
| Encoding | UTF-8 or US-ASCII; encoding declared in optional leading XML processing instruction |
| Compression | None - uncompressed plain text |
| Typical size | 1 KB - 500 KB (simple DTDs are small; complex standards like DITA or DocBook DTDs can be 100+ KB with modular .mod/.ent files) |
| Declaration types | <!ELEMENT> (child elements and content model), <!ATTLIST> (attributes and defaults), <!ENTITY> (text macros), <!NOTATION> (notation types) |
| Standard origin | SGML ISO 8879 (October 1986); adopted by W3C XML 1.0 Recommendation (February 1998) |
| Namespace support | None - DTD syntax predates XML namespaces, a key limitation versus XSD |
| Data type support | Limited to ID, IDREF, CDATA, NMTOKEN, and a few others - no rich types such as date or integer |
| Validation | XML parsers can validate a document against its DTD using ELEMENT and ATTLIST constraints |
| HTML5 DOCTYPE | <!DOCTYPE html> is a minimal stub; does not reference or require an actual DTD file |
| Well-known public DTDs | XHTML 1.0, DocBook, DITA, SVG 1.1, MathML 2.0 - referenced by PUBLIC/SYSTEM identifiers in documents |
| Superseded by | W3C XML Schema (.xsd, 2001) and RELAX NG (.rnc/.rng, 2003) for namespace-aware and richly-typed validation |
| Released | 1986 (SGML, ISO 8879); 1998 for XML DTD (W3C XML 1.0 Recommendation, February 1998) |
| Latest version | XML 1.0 Fifth Edition (November 2008); XML 1.1 Second Edition (August 2006) - DTD syntax unchanged since 1998; W3C XML Schema (XSD) and RELAX NG are modern replacements |
| Open standard | Yes · royalty-free |
| Specification | www.w3.org |
DTD conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about DTD files.