Document Types

An XHTML Document Type Definition (DTD) describes in precise, computer-readable language the syntax or grammar that is allowed for XHTML markup. When an XHTML document is created, the DTD that it conforms to is declared at the top of the document. XHTML 1.0 specifies three XML document types that correspond to the three HTML 4.0 DTDs: Strict, Transitional, and Frameset. XHTML 1.1 and XHTML 2.0 may also be specified as DTDs.

Here is an example of each DTD declaration:

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN" "">

The DTD definition is placed at the beginning of the document before the opening <html> tag, as shown in Example 12-1.

Example 12-1. A document defined as xhtml 1.0 strict

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""> <html xmlns="" xml:lang="en" lang="en"> <head>

<title>Document Type Declaration Example</title> </head> <body>

<p>The content of the page goes here.</p> </body> </html>

The opening line:

<?xml version="1.0" encoding="UTF-8"?>

This isn't strictly required unless you're using a different character encoding than UTF-8.

Was this article helpful?

0 0

Post a comment