XHTML reformulates the existing HTML technology to be an application of XML. It is already used for mobile phone and PDA Internet sites, and expected to gain widespread use as XML becomes more popular. Dan Wellman explains the differences between XHTML and HTML 4, and shows how easy it is to make the switch.
An Introduction to XHTML - Conform to the rules (Page 3 of 5 )
As XHTML is an application of XML, it must conform to the same rules as XML and as such, all XHTML documents must be well formed. As with XML, XHTML documents must contain a root element. This element is the HTML element and serves as the container for all other elements. Adhering to the rules defined above will also ensure your document is well formed.
One of the few contrasts between XML and XHTML is that XHTML documents, in addition to being well formed, must also be valid, meaning that your document must adhere to a DTD. With XML, this is of course optional. For anyone who doesn't know, a DTD or Document Type Definition is a set of syntax rules that the document associated with it must adhere to. These syntax rules are different from the structure rules explained above, in that they advise of elements that must appear, and in what order they appear. For example, the XHTML transitional DTD includes the following segment of code:
<!ELEMENT html (head, body)>
which declares that the Document root (the HTML element) must contain a head and a body element, in that order. These elements are child elements of the HTML element. The actual DTD is a lot more complex than the example above.
There are three different versions of XHTML DTD that you can use in your XHTML documents; Strict, Transitional and Frameset. The Strict variant allows elements relating to document structure but does not allow most presentational elements. This version should be used in conjunction with CSS (Cascading Style Sheets) that handle the document presentation. The Transitional variant allows most elements including presentational elements, and many of the HTML 4 specification deprecated elements. This is useful if you are updating a site to be XHTML compliant but do not want to make the leap to a style sheet driven site. The frameset variant is similar to the transitional variant but also allows the use of frameset elements.
To reference whichever DTD you plan to use in your XHTML document, simply add the following DOCTYPE declaration to your document, before the root element:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1DTD/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">
Broken down into its respective parts, the above statements consist of the document type: <!DOCTYPE html, the DTD type: PUBLIC, the DTD identifier: "-//W3C//DTD XHTML 1.0 Transitional//EN", and the DTD location: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.
Another main difference between XML and XHTML is that in XML, the XML declaration is mandatory but in XHTML, it is optional. The W3C still strongly recommends that developers use the XML declaration in their documents for reasons of future compatibility. If used, this should be the first statement of the document with no white-space preceding it.
Many other structures within XHTML are almost exactly the same as those in HTML 4; the linking specification, for example, is the same. In many ways it is a shame that the extensible linking structure of XML (XLINK) was not used as the base of XHTML's linking structure as we could now be using links with more than one destination, automatically traversed links and all kinds of other cool things. Instead, XHTML has inherited HTML 4's linking structure, which works in exactly the same way as it always has. Maybe this is something that future XHTML specifications will bring to the table. We can but hope.