Differences between XHTML and HTML

Original Author(s): Markus Gylling

In spite of the grammatical similarity between XHTML and HTML in terms of element and attribute names, there are some significant differences between these languages.

The differences are significant because they have an impact on the wellformedness constraints of XML. In other words, a document that does not comply with the syntax rules that XHTML add, will not even be wellformed, and can therefore never be valid.

If you do not remember or do not understand what wellformedness and validity is, you are advised to read the XML Syntax Introduction.

Tag minimization

HTML does not require all elements to have closing tags.

In HTML, this (called "tag minimization") is allowed:

 <h1>Chapter 1</h1>
 <p>Paragraph text
 <h2>Chapter 1.1</h2>

Of course, in XML this document would be malformed because the <p> element is not closed.

Case sensitivity

HTML is case insensitive, but XHTML (as all XML) is case sensitive.

In HTML, this is allowed:

 <h1>Chapter 1</H1>

In XML all element and attribute names are case sensitive. The example above is malformed XML.

In XHTML all element and attribute names must be lowercase.

<p> is a paragraph, but <P> is an unknown element.

Empty Element Syntax

The syntax for empty elements is different.

In HTML, empty element syntax is <elementName>

In XHTML empty element syntax is <elementName />

Attribute Values

Attribute values must be enclosed by single or double quotes.

In HTML, this is allowed: <meta name=keywords>

In XHTML it must read <meta name="keywords" /> or <meta name='keywords' />

Boolean attributes

Minimized attributes are now allowed in XHTML/XML

In HTML, a boolean attribute could be expressed <p nowrap>

In XHTML, is must read <p nowrap="nowrap">

Fragment Identifiers

Use of the name attribute was deprecated in XHTML 1.0, in favor of the id attribute.

Many existing HTML clients don't support the use of ID-type attributes in this way, so identical values may be supplied for both of these attributes to ensure maximum forward and backward compatibility:

<a id="target1" name="target1">...</a><br/> <br/>

Read More

DAISYpedia Categories: 

This page was last edited by PVerma on Friday, August 6, 2010 23:24
Text is available under the terms of the DAISY Consortium Intellectual Property Policy, Licensing, and Working Group Process.