Quick Introduction to XHTML

In this lesson of the XML tutorial, you will learn...
  1. The benefits of XHTML.
  2. The difference between XHTML and HTML.
  3. The different XHTML specifications.
  4. How to create an XHTML document.

XHTML Benefits

XHTML is the XML version of HTML. The major benefits of XHTML over HTML are:

  • Non-HTML aware user agents can read XHTML documents.
  • XHTML documents can easily be transformed into other document types with XSLT or other languages.

XHTML vs. HTML

XHTML documents differ from HTML documents in the following ways.

  • Documents must be well-formed according XML syntax rules.
  • Element and attribute names must be in lowercase letters.
  • Container elements must have end tags. For example, list items must be closed with a </li> tag.
  • Attribute values must be in single or double quotes.
  • Attributes may not be minimized. Attributes that have no defined value should use the attribute name for their value.
    <!--Invalid-->
    <select name='flavor' multiple>
    
    <!--Valid-->
    <select name='flavor' multiple='multiple'>
  • Empty elements must be closed, either with a standard end tag or a shortcut close.
    <!--Invalid-->
    <hr>
    
    <!--Valid-->
    <hr></hr>
    
    <!--Also Valid-->
    <hr/>
  • Script and Style elements contain PCDATA, meaning that they will be parsed as XML. Because these elements often contain special XML characters such as < and &, this can cause problems. To be safe, the content of script and style elements should be wrapped in CDATA sections as shown below.
    <script type="text/javascript">
     <![CDATA[
      //script content
     ]]>
    </script>

For additional information on the differences between XHTML and HTML, see http://www.w3.org/TR/xhtml1/#diffs.

The DOCTYPE Declaration

There are three DTDs for XHTML: Strict, Transitional, and Frameset. All XHTML documents must conform to the XML syntax rules.

XHTML Strict

XHTML Documents that conform to the Strict DTD may not use any deprecated HTML tags. The DOCTYPE declaration looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

XHTML Transitional

XHTML Documents that conform to the Transitional DTD may use deprecated HTML tags, but may not use the <frameset> and <frame> tags. The DOCTYPE declaration looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1
 transitional.dtd">

XHTML Frameset

XHTML Documents that conform to the Frameset DTD may use deprecated HTML tags including the <frameset> and <frame> tags. The DOCTYPE declaration looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

The Document Element

In XHTML, the document element (<html>) must contain a namespace declaration as shown below.

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

A Sample XHTML Document

Below is an example XHTML document.

Code Sample: XHTML/Demos/Xml101.html

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Introduction to XML</title>
</head>
<body>
<h1>Introduction to XML</h1>
<div id="courseNum">XML101</div>
<div id="courseLength">3 days</div>
<h2>Prerequisites</h2>
<ul>
 <li>Experience with Word Processing</li>
 <li>Experience with HTML (optional, but recommended)</li>
</ul>
<h2>Course Outline</h2>
<div id="outline">
<ul>
 <li>
  XML Basics
  <ul>
   <li>What is XML?</li>
   <li>
    XML Benefits
    <ul>
     <li>XML Holds Data, Nothing More</li>
     <li>XML Separates Structure from Formatting</li>
     <li>XML Promotes Data Sharing</li>
     <li>XML is Human-Readable</li>
     <li>XML is Free</li>
    </ul>
   </li>
  </ul>
  <ul>
   <li>
    XML Documents
    <ul>
     <li>The Prolog</li>
     <li>Elements</li>
     <li>Attributes</li>
     <li>CDATA</li>
     <li>XML Syntax Rules</li>
     <li>Special Characters</li>
    </ul>
   </li>
  </ul>
  <ul>
   <li>Creating a Simple XML File</li>
  </ul>
 </li>
</ul>
</div>
</body>
</html>

Quick Introduction to XHTML Conclusion

In this lesson of the XML tutorial, you learned the difference between HTML and XHTML.

To continue to learn XML go to the top of this page and click on the next lesson in this XML Tutorial's Table of Contents.

Use of this website implies agreement to the following:

Copyright Information

All pages and graphics on this Web site are the property of Webucator, Inc. unless otherwise specified.

None of the content on this website may be redistributed or reproduced in any way, shape, or form without written permission from Webucator, Inc.

No Printing or saving of web pages

This content may not be printed or saved. It is for online use only.


Linking to this website

You may link to any of the pages on this website; however, you may not include the content in a frame or iframe without written permission from Webucator, Inc.


Warranties

This website is provided without warranty of any kind. There are no guarantees that use of the site will not be subject to interruptions. All direct or indirect risk related to use of the site is borne entirely by the user. All code and explanations provided on this site are provided without warranties to correctness, performance, fitness, merchantability, and/or any other warranty (whether expressed or implied).

For individual private use only

You agree not to use this online manual to deliver or receive training. If you are delivering or attending a class that is making use of this online manual, you are in violation of our terms of service. Please report any abuse to courseware@webucator.com. If you would like to deliver or receive training using this manual, please fill out the form at http://www.webucator.com/Contact.cfm.