XHTML Document Declarations
Every XHTML file must begin with
declarations that tell the browser which versions of XML and XHTML
are used in the document. The browser uses this information to
display the document correctly. In Chapter 9 we
saw how a DOCTYPE declaration can be added to the
beginning of an HTML document. For XHTML, this element is required.
The following is a minimal XHTML document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Title is required</title>
</head>
<body>
..content of document...
</body>
</html>Let’s look at this sample one element at a time. The document
begins with an XML declaration (beginning with
<? and ending with ?>)
that tells the XML processor that the document uses XML Version
1.0.[11] The encoding attribute
specifies the 8-bit Unicode character set (the most common). Be sure
that the encoding value matches the character set used in your
document (see Chapter 7 for more information on
character sets).
The next element is the DOCTYPE declaration (the
same as we’ve seen in XML and even regular HTML documents) that
references the Transitional DTD, both by a public identifier and via
a URL. If your document follows the strict XHTML version, use this
declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access