Show Me XHTML
EXtensible HyperText Markup Language
 
 

The following is both a reference and a practical example of the application of XHTML to a web page. To view the code for this page, select "view source" from your browser menue.

XHTML — EXtensible HyperText Markup Language

XHTML is essentially HTML, but with a more strict application and a few syntax differences. Recommended by the W3C in 2000, it is a preferred version of HTML specifically for use with XML applications. The following describes how XHTML is different from HTML:

  • Must be well-formed. Most browsers interpret poorly formed HTML which has created a proliferance of "breaking the rules". Code MUST be compliant:
    - Elements must be properly nested: <b><i>text</i></b>
    - All tags properly closed
    - Must have one root element: <html></html>
    - All attribute values enclosed in quotes.
  • Syntax should be in lowercase.
  • Tags without a closing tag should include a space and "/" to close the tag: <br />
  • Tags with un-quoted attributes should be quoted - example:
    <input checked> should be <input checked=”checked” />
  • The "id" attribute replaces the "name" attribute. Both "id" and "name" may be used for compatibility with older browsers.

DOCTYPE declaration
Must have a DOCTYPE declaration - Note: The DOCTYPE declaration is not a part of the XHTML and should not have a closing tag. Should always be the first line. Example:

<!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">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <title>Untitled Document</title>
</head>
<body>
</body>
</html>

There are three XHTML DTDs (declared in DOCTYPE):

  • STRICT – when you want really clean markup, free of presentational clutter. Use together with CSS.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  • TRANSITIONAL - when you want to still use HTML's presentational features
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  • FRAMESET – use with framesets (obviously)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

The Lang Attribute
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element. If you use the lang attribute in an element, you must add the xml:lang attribute, like this:
<div lang="no" xml:lang="no">Heia Norge!</div>

XHTML Modules
W3C has split the definition of XHTML into 28 modules:

Module Name Description
Applet Module Defines the deprecated* applet element
Base Module Defines the base element
Basic Forms Module Defines the basic forms elements
Basic Tables Module Defines the basic table elements
Bi-directional Text Module Defines the bdo element
Client Image Map Module Defines browser side image map elements
Edit Module Defines the editing elements del and ins
Forms Module Defines all elements used in forms
Frames Module Defines the frameset elements
Hypertext Module Defines the a element
Iframe Module Defines the iframe element
Image Module Defines the img element
Intrinsic Events Module Defines event attributes like onblur and onchange
Legacy Module Defines deprecated* elements and attributes
Link Module Defines the link element
List Module Defines the list elements ol, li, ul, dd, dt, and dl
Metainformation Module Defines the meta element
Name Identification Module Defines the deprecated* name attribute
Object Module Defines the object and param elements
Presentation Module Defines presentation elements like b and i
Scripting Module Defines the script and noscript elements
Server Image Map Module Defines server side image map elements
Structure Module Defines the elements html, head, title and body
Style Attribute Module Defines the style attribute
Style Sheet Module Defines the style element
Tables Module Defines the elements used in tables
Target Module Defines the target attribute
Text Module Defines text container elements like p and h1
* Deprecated elements should not be used in XHTML.