1. Home
  2. Computing & Technology
  3. Web Design / HTML

DTDs and Markup Languages

Document Type Definitions are the Basis of Markup Languages

By Jennifer Kyrnin, About.com

When you write HTML with some editors, you'll notice that there is this strange line written across the top<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">. While you may not know what it is, it still serves a purpose, and with XML that line of code is required to write a well-formed document.

This line is the "Document Type Declaration" that defines the "Dcoument Type Definition" or DTD. In the HTML declaration<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">there are four parts:

  1. DOCTYPE
    this tells the browser that this tag is a Document Type Declaration
  2. HTML
    the name of the DTD
  3. PUBLIC
    the DTD is available publicly
  4. -//W3C//DTD HTML 4.0 Transitional//EN
    the actual DTD used for the document, in this case HTML 4.0 Transitional in English

What is a DTD?

A DTD in an XML or HTML document provides a list of the elements, attributes, comments, notes, and entities contained in the document. It also indicates their relationship to one another within the document. In other words, a DTD is the grammar of an XML or HTML document.

Purpose of a DTD

When using a DTD for an XML document (including XHTML), the DTD is there to provide structure for your documents. It is easy to write an XML document, but without the DTD, it has no syntactic meaning to the computer. For example, if you come across this portion of an XML document:<address>
<street>123 Any Street</street>
<city>Jackson</city> <state>MI</state>
</address>While you would know it was an address, you wouldn't know whether it was an address the computer was supposed to create from a database table, if that address was for mailing, and other things. The computer, on the other hand, wouldn't see this as anything more than a string of text. If you viewed it in an XML browser, you might not get any errors, but you also wouldn't get a very interesting or useful page.

In other articles, we'll explore the inner workings of a DTD, and examine the elements that make up a DTD. You'll learn what an element, attribute, entity, and notation is and how to use them within your own DTDs. Plus, you'll learn how to read other DTDs so that you can use them in your own XML documents.

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. XML
  5. DTDs
  6. Document Type Definitions (DTDs) and Markup Languages

©2008 About.com, a part of The New York Times Company.

All rights reserved.