XHTML
Extensible Hypertext Markup Language (XHTML) is a markup language that has the same expressive possibilites as HTML, but a stricter syntax. Whereas HTML was an application of SGML, a very flexible markup language, XHTML is an application of XML, a more restrictive subset of SGML. XHTML 1.0 became a World Wide Web Consortium (W3C) Recommendation on January 26, 2000.
XHTML is the successor to and the current version of HTML. The need for a more strict version of HTML was felt primarily as now web content needs to be delivered to many devices (like mobile devices) apart from traditional computers, where extra resources cannot be devoted to support the generosities of HTML (the looser the syntax of a language, the harder it is to process). The XHTML DTD is defined within the XML DTD to enforce the strict rules of XML.
Most of the recent versions of popular web browsers render XHTML properly, and many older browsers will also render XHTML as it is mostly a subset of HTML and most browsers do not require valid HTML. Similarly, almost all web browsers that are compatible with XHTML also render HTML properly. Some say this is slowing the switch from HTML to XHTML.
XHTML's true power is realized when used in conjunction with Cascading Style Sheets. This makes the separation of content and form an integral part of the web page's code.
The changes from HTML, to transitional XHTML, are minor, and are mostly just in conformance with XML. The most important change is the requirement that all tags are well-formed. Additionally, in XHTML, all elements must be lowercased. This is in direct contrast to established traditions which began around the time of HTML 2.0, when most people preferred uppercased tags. In XHTML, all attributes, even numerical ones, must be quoted. (This was mandatory in HTML as well, but often ignored.) All tags must also be closed, even the empty tags <img> and <br>. This can be done by adding a closing slash to the tag: <img /> and <br />. Attribute minimization (e.g., <option selected>) is also prohibited. More differences are detailed at the W3C XHTML specification (http://www.w3.org/TR/xhtml1/#diffs).
Wikipedia pages currently use valid XHTML 1.0 Transitional.
Versions of XHTML
XHTML is HTML reformulated as XML. There are three different versions, equal in scope to their respective HTML4.0 versions.
- XHTML 1.0 Transitional: Intended for easy migration from HTML3.2, or for those using link targets or inline-frames
- XHTML 1.0 Strict: Separates content from layout (which now moves to CSS)
- XHTML 1.0 Frameset: For splitting the browser window into several frames
- XHTML 1.1: Module-based XHTML; authors can import additional features (such as framesets) into their markup. This version also allows for ruby markup support, needed for Far-Eastern languages.
- XHTML Basic: A special "light" version of XHTML for devices which cannot use the full XHTML set, primarily used on handhelds such as mobile phones. This is the intended replacement for WML and C-HTML.
- XHTML Mobile Profile: Based on XHTML Basic, this Nokia effort targets hand phones specifically by adding mobile phone-specific elements to XHTML Basic
Work on XHTML 2.0 is, as of 2004, still underway. The XHTML 2.0 draft is controversial because it breaks backwards compatibility with all previous versions, and is therefore in effect a new markup language inspired by (X)HTML rather than a true successor of it.
Validating XHTML Documents
An XHTML document that conforms to the XHTML specification is said to be a valid document. In a perfect world, all browsers would follow the web standards and valid documents would predictably render on every browser and platform. Although validating your XHTML does not ensure cross-browser compatibility, it is reccommended. A document can be checked for validity at the W3C Markup Validation Service, found in this article's External Links.
For a document to validate, it must contain a Document Type Declaration. A DTD should be placed at the very beginning of an XHTML document. These are the three common XHTML DTDs:
- XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
- XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
- XHTML 1.0 Frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd">
- XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "DTD/xhtml11.dtd">
A character encoding should also be specified at the beginning of an XHTML document. Once an XHTML document has a doctype and character encoding specified, it can be run through the a validater (such as the W3C Markup Validation Service) to see if it meets the standard. Validation will locate and describe errors in XHTML markup.
Some of the most common errors in XHTML are:
- Unclosed elements (XHTML, unlike HTML, requires all elements be closed)
- Failing to specify alternate text for images ("ALT Tags", which help make pages accessible for devices that don't load images or screen-readers for the blind)
- Putting text directly in the body of the document
- Nesting block-level elements within inline elements
- Forgetting to put quotation marks around attribute values
- Improperly nesting elements
- Improperly using entities (such as & instead of &).
This is not an exhaustive list, but gives a general sense of errors that XHTML coders often make.
When a page is validated using the W3C Markup Validation Service, the W3C returns a small icon that you may place on your document to show that it conforms to web standards. The W3C also offers validation for CSS and HTML documents.
External links
- W3C's HTML Home Page (http://www.w3.org/MarkUp/)
- XHTML 1.0 Specification (http://www.w3.org/TR/xhtml1/)
- XHTML 1.1 Specification (http://www.w3.org/TR/xhtml11/)
- Working Draft of XHTML 2.0 (http://www.w3.org/TR/xhtml2/)
- W3C MarkUp Validation Service (Including XHTML validation) (http://validator.w3.org/)
- XHTML validator on SourceForge (http://validate.sf.net)
- Wikibooks XHTML tutorial (http://www.wikibooks.org/wiki/Programming:XHTML) — in progress

