Advertisement

XHTML

From Academic Kids

Extensible Hypertext Markup Language, or XHTML, is a markup language that has the same expressive possibilities 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. Because they need to be well-formed XML documents, XHTML documents offer greater potential for automated processing than older flavors of HTML. XHTML 1.0 became a World Wide Web Consortium (W3C) Recommendation on January 26, 2000.

Contents

Overview

Missing image
W3C_valid_XHTML_1.0_icon.png
The W3C offers this icon, which may be placed on valid XHTML documents once they pass through the W3C Markup Validator (http://validator.w3.org/).

XHTML is the successor to, and the current version of, HTML. The need for a more strict version of HTML was felt primarily because World Wide Web content now 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. A DTD (Document Type Definition) defines the rules of XHTML, against which documents can be checked.

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.

An especially useful feature of XHTML is that different XML namespaces (such as MathML and SVG) can be incorporated within it.

The changes from HTML to transitional XHTML are minor, and are mainly to achieve conformance with XML. The most important change is the requirement that the document must be well formed and all elements must be closed. Additionally, in XHTML, all tags must be written in lowercase. This is in direct contrast to established traditions which began around the time of HTML 2.0, when most people preferred uppercase tags. In XHTML, all attributes, even numerical ones, must be quoted. (This is not mandatory in SGML (hence in HTML), where quotes are not required if the content consists only of alphanumeric and certain allowed special characters.) All elements must also be closed, including empty elements such as img and br. This can be done by adding a closing slash to the start tag: <img … /> and <br />. Attribute minimization (e.g., <option selected>) is also prohibited; instead, use <option selected="selected">. More differences are detailed in the W3C XHTML specification [1] (http://www.w3.org/TR/xhtml1/#diffs).

Versions of XHTML

XHTML 1.0

The original XHTML W3C Recommendation, XHTML 1.0, was simply a reformulation of HTML 4.01 in XML. There are three different 'flavors' of XHTML 1.0, each equal in scope to their respective HTML 4.01 versions.

  • XHTML 1.0 Strict requires that documents must be well-formed, and is the same as HTML 4.01 Strict in XML form.
  • XHTML 1.0 Transitional allows some common deprecated elements and attributes not found in XHTML 1.0 Strict to be used, such as <center>, <u>, <strike>, and <applet>.
  • XHTML 1.0 Frameset: Allows the use of HTML framesets.

XHTML 1.1

The most recent XHTML W3C Recommendation is 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 East-Asian languages (especially CJK).

This is the specification that the W3C recommends all new web pages be created in.

The XHTML 2.0 draft specification

Work on XHTML 2.0 is, as of 2005, still underway; in fact, the DTD has not even been authored yet. 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 created to circumvent (X)HTML's limitations rather than being simply a new version.

New features brought into the HTML family of markup languages by XHTML 2.0 state that:

  • HTML forms will be replaced by XForms.
  • HTML frames will be replaced by XFrames.
  • The DOM Events will be replaced by XML Events, which uses the XML Document Object Model.
  • A new list element, the <nl> element, will be included in order to specifically designate a list as a navigation list. This will be useful in creating nested menus which are currently created by a wide variety of means.
  • Any element will be able to contain a hyperlink, e.g., <li href="articles.html">Articles</li>.
  • Any element will be able to reference alternative media with the src attribute, e.g., <p src="lbridge.jpg" type="image/jpeg">London Bridge</p> will replace <img src="lbridge.jpg" alt="London Bridge" />.
  • The <img src="" alt="" /> element has been removed in favor of <object type="MIME/ContentType" src="">Alt</object>
  • The heading elements (i.e. <h1>, <h2>, <h3>, etc.) will be deprecated in favour of the single element <h>. Levels of headings will instead be indicated by the nested <section> elements each with their own <h> heading.
  • The presentational elements <i>, <b> and <tt>, still allowed in XHTML 1.x (even Strict), will be absent from XHTML 2.0. The only presentational elements remaining will be <sup> and <sub> for superscript and subscript respectively.

Others in the XHTML family

  • 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 OMA (Open Mobile Alliance (http://www.openmobilealliance.org/|)) effort targets hand phones specifically by adding mobile phone-specific elements to XHTML Basic.

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 recommended. A document can be checked for validity with the W3C Markup Validation Service.

DOCTYPEs

For a document to validate, it must contain a Document Type Declaration, or DOCTYPE. A DOCTYPE declares to the browser what Document Type Definition (DTD) the document conforms to. A DTD should be placed at the very beginning of an XHTML document. These are the most common XHTML DTDs:

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

Character encoding may be specified at the beginning of an XHTML document in the XML declaration and within a meta http-equiv statement. (If an XML document lacks encoding specification, an XML parser assumes that the encoding is UTF-8 or UTF-16, unless the encoding has already been determined by a higher protocol.)

Common errors

Some of the most common errors in XHTML are:

  • Not closing empty elements (elements without closing tags)
    • Incorrect: <br>
    • Correct: <br />
  • Not closing non-empty elements
    • Incorrect: <p>This is a paragraph.<p>This is another paragraph.
    • Correct: <p>This is a paragraph.</p><p>This is another paragraph.</p>
  • Improperly nesting elements (elements must be closed in reverse order)
    • Incorrect: <em><strong>This is some text.</em></strong>
    • Correct: <em><strong>This is some text.</strong></em>
  • Not specifying alternate text for images (using the alt attribute, which helps make pages accessible for devices that don't load images or screen-readers for the blind)
    • Incorrect: <img src="/skins/common/images/poweredby_mediawiki_88x31.png" />
    • Correct: <img src="/skins/common/images/poweredby_mediawiki_88x31.png" alt="MediaWiki" />
  • Putting text directly in the body of the document
    • Incorrect: <body>Welcome to my page.</body>
    • Correct: <body><p>Welcome to my page.</p></body>
  • Nesting block-level elements within inline elements
    • Incorrect: <em><h2>Introduction</h2></em>
    • Correct: <h2><em>Introduction</em></h2>
  • Not putting quotation marks around attribute values
    • Incorrect: <td rowspan=3>
    • Correct: <td rowspan="3">
  • Using the ampersand outside of entities (use &amp; to display the ampersand character)
    • Incorrect: <title>Cars & Trucks</title>
    • Correct: <title>Cars &amp; Trucks</title>
  • Using uppercase tag names and/or tag attributes
    • Incorrect: <BODY><P>The Best Page Ever</P></BODY>
    • Correct: <body><p>The Best Page Ever</p></body>
  • Attribute minimization
    • Incorrect: <textarea readonly>READ-ONLY</textarea>
    • Correct: <textarea readonly="readonly">READ-ONLY</textarea>

This is not an exhaustive list, but gives a general sense of errors that XHTML coders often make.

Backward compatibilities

XHTML 1.0 is backward compatible with HTML when served as text/html. However, there are problems associated, especially for Internet Explorer. For more information, please refer to XHTML section in the criticisms of Internet Explorer article. Furthermore, XHTML 2.0 has been faulted for not being backward compatible with XHTML 1.x efforts.

Example

The following is an example of XHTML 1.0 Strict.

<?xml version="1.0" encoding="UTF-8"?>
<!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" xml:lang="en" lang="en">
    <head>
        <title>XHTML Example</title>
    </head>
    <body>
        <p>This is tiny example of an XHTML usage.</p>
    </body>
</html>

See also

External links

Template:Wikibookspar

Validators

cs:XHTML de:Extensible Hypertext Markup Language es:XHTML eo:XHTML fr:XHTML ia:XHTML it:XHTML he:XHTML lv:XHTML nl:XHTML ja:XHTML no:XHTML pl:XHTML pt:XHTML ru:XHTML sk:XHTML fi:XHTML sv:XHTML vi:XHTML zh:XHTML

Navigation

Academic Kids Menu

  • Art and Cultures
    • Art (http://www.academickids.com/encyclopedia/index.php/Art)
    • Architecture (http://www.academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (http://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (http://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools