The Rules of XHTML

There are seven rules (actually four rules and three suggestions) for creating a valid XHTML document. These basic rules must be followed for a well-formed XML document to be considered a valid XHTML document. If you want a pre-fab page that incorporates these rules, just cut and paste from this template.

1) Documents start with XML / DTD declarations

Although the XML declaration is technically an option as defined by the W3C, it is good form to begin every XML document with a command indicating that what follows is XML. The minimum XML declaration is <?xml version="1.0"?>. Following the XML declaration, another line needs to be added telling the browser where to find the additional rules (DTD) that changes this from just XML to XHTML. This declaration is <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> and should appear as the second statement in the document.

2) The HTML element must refer to a namespace

To avoid confusion between the W3C approved element names, and any created by the author, the HTML element must refer to a default namespace. This is done by including an HTML element (as the root element) the is formatted like this <html xmlns="http://www.w3.org/1999/xhtml">.

3) XHTML has four required tags

Every valid document must include an <html> tag as the root element. The direct descendants of this root element must be <head> and <body>, and within the <head> element the first sub-element must be the <title> element.

4) All element and attribute names must be lower-case

In an attempt to avoid confusion, and since XML is case sensitive, all XHTML element and attribute names are required to be lower-case.

5) Use the "id" and "name" attributes

Although not a requirement, since strict XML applications will only use "id" as an identifier attribute, and not all browsers recognize the "id" attribute, it is probably best to use both "id" and "name" when identifying an element.

6) Use style sheets to control layout

Although not a requirement, the W3C suggests the use of cascading style sheets and style attributes to control the formatting of the data. This suggestion also applies to HTML version 4.0 formatting.

7) Externalize scripts and styles

Although not a requirement, the W3C strongly suggests that and script or style information be placed in an external file. This helps avoid stray special characters like an "<" or "&" from being incorporated into the data.

condensed from "Beginning XML" by David Hunter and "Beginning XHTML" by Frank Boumphrey et.al.