Before going through the overall structure of an XHTML document, let's briefly define some of the terms we will most often encounter.
<h1>
) as well as any attributes. The end tag, instead, doesn't contain any attribute and precedes the element name with a forward slash ("/", e.g. </h1>
). XHTML is case sensitive and all element names are lower-case. The content of an element is everything between the start and end tags; it can be made up of other elements, text or both.The first element of an XHTML document is the XML declaration. It is not required (though strongly recommended by the W3C recommendation) if the character encoding is the default (UTF-8 or UTF-16) or was determined by a higher-level protocol. In all other cases, it is mandatory:
<?xml version="1.0" encoding="UTF-8"?>
Note: though recommended, the XML declaration may have odd "side effects" in Internet Explorer. Therefore, if you need absolute control over the page layout, don't use it.
After the XML declaration, there must be the DOCTYPE declaration, which must reference one of the three legal DTDs using the respective Formal Public Identifier. Legal DTDs are the following (they are identical to HTML 4 DTDs except for changes due to the differences between XML and SGML):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Finally, the last requisites of a strictly conforming document are:
html
;xmlns
declaration for the XHTML namespace;http://www.w3.org/1999/xhtml
.Therefore, the root element of the document looks like:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> [...] </html>
So, to recap, the overall structure of an XHTML 1.0 document looks like:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <!-- Headers --> </head> <body> <!-- Document body --> </body> </html>