Home arrow HTML arrow Page 5 - 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 - Namespace awareness
(Page 5 of 5 )


In keeping with XML, XHTML is also namespace aware and in both 1.0 and 1.1 XHTML specifications, the root or html element must contain the following namespace URL:

<html xmlns="http://www.w3.org/1999/xhtml">

Additional namespaces can be declared in any child or grandchild and subsequent elements of the root element in the same way. For the more simple XHTML documents, this should not be necessary, but when you get to the stage where you are adding your own XHTML elements (the X still stands for eXstensible after all!), declaring additional namespaces and their associated prefix becomes increasingly necessary. It is through this technique that two of the same elements that mean different things can be used in the same document.

For example, your XHTML document must include a body element, but what if you want to produce a page containing numerous articles, each with a <headline> and <body> element? You could simply associate the prefix dxml (Dans XML) with your own unique namespace directly after the mandatory namespace declaration of the root element:


Then use the body element of your articles with the assigned prefix:

<dxml:body>This is the body of an article</dxml:body>

When creating XHTML documents, you have to save them with a HTM extension (that is at least the common practice), therefore what you're really saving are normal HTML documents, and any elements that are not correctly formed will still work. An excellent way of testing your XHTML documents for well-formedness is to save them as XML documents instead. To illustrate what I mean, type the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHMTL 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <title>Example Strict XHMTL Document</title>
    <h1>An example Strict XHTML Document</h1>
    <p><font face="arial">The font tag is deprecated in XHTML Strict and XHTML 1.1</p>

Save the file with an HTM extension and load the page in a browser, it will work perfectly. But save the above code with an XML extension and try and load it in a browser. You will get a message advising "End tag 'p' does not match the start tag 'font'." Add the closing font tag (in the correct nesting order of course) and the document should display normally. This will not vet your documents for deprecated tags, but it should catch any syntactical errors.

As I've stressed throughout this article, XHTML is really easy if you've worked with HTML and pretty easy even if you haven't. I've tried to cover the basic building blocks of the language, but don't be fooled, there is far more that you can do with it than I have space to describe here. XHTML is the way of the future, use it! What more can I say?

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials