As we mentioned in the previous tutorial, an XHTML document contains the DOCTYPE declaration, and required html, head and body sections. It is very important to place the Doctype declaration on the first line and all other mentioned tags in the corresponding order.
The above affirmation gives us the following document
xhtml<!DOCTYPE ...>
<html>
<head>
<title> ... </title>
</head>
<body> ... </body>
</html>
The Document Type Definitions or DTD defines a set of rules that will be used when reading and validating the document. There are three Document Type Definitions (DTD)
For a better understanding we will show an example for every one of them.
XHTML 1.0 Strict
xhtml<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
XHTML 1.0 Strict is used when we will use a very clean markup, with absolutely no HTML exclusive tag.
XHTML 1.0 Transitional
xhtml<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
XHTML 1.0 Transitional it's the most used of all and it allows you to use XHTML markup and HTML markup that does not contradicts the XHTML rules
XHTML 1.0 Frameset
xhtml<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";>
XHTML 1.0 Frameset it is only used when the document contains HTML frames.
According to all this our first document will now look like this:
xhtml<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html>
<head>
<title>Valid XHTML document</title>
</head>
<body>
<p>According to this definitions a valid XHTML document will have this structure</p>
</body>
</html>
We can now conclude that XHTML it's a much cleaner version of HTML 4.01. The prevent errors when you write long XHTML code, it is a good practice to run a validator on it. You can find one at w3.org, but we will talk about that in the next tutorial.