Home arrow HTML arrow Page 3 - An Introduction to XHTML

An Introduction to XHTML

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.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 42
December 01, 2004
  1. · An Introduction to XHTML
  2. · No lazy programming allowed
  3. · Conform to the rules
  4. · The table structure
  5. · Namespace awareness

print this article

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"

Or even:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"

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.

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials