by February 7, 2003 0 comments



XHTML is a markup language written in XML. It is a W3C recommendation, first published in January 2000. The second edition was released in August 2002. As our title suggests, XHTML is being considered as the next version of HTML. There are many reasons for this, including the numerous problems with
existing HTML. 

Current HTML does not enforce syntactical rules due to which a lot of ‘bad’ HTML is floating around on the World Wide Web. As long as Web pages are viewed only through desktop computers connected to the Net, there is not much of an issue, because Web browsers are easy on bad HTML, and render pages more or less as they are meant to be seen. Web browsing, however, is also poised to move on to devices like cellphones and PDAs (even wrist-watches and refrigerators!), where the necessary small size of the browser-equivalent applications would not be able to handle badly written HTML. They will just reject it. Enter XHTML. Being XML based, it’s Extensible, meaning you can use XML-based tags. Plus it also enforces conformance to syntax. 

New elements 
New elements or element attributes that can be easily added to XML are provided through XHTML’s ‘modularity.’ So XHTML can (and will) have different sets or modules for specific purposes such as handheld devices and special-purpose appliances. These modules can also be upgraded or replaced independently of other modules. XHTML1.1 incorporates this feature and XHTML2.0, which is in its third draft, will enhance it as it becomes more stable. But the designs are apparently in place, so we can expect them soon. 

Let us address the conformance to the syntax part. The following main rules must be followed to get your Web page to be validated as XHTML compliant.

Well-formed documents
This means, that like in XML, XHTML documents must have properly closed tags and proper nesting. See the following example.

Incorrect:
<b> This is <i>wrong</b> </i>

Correct:
<b> This is <i>correct</i> </b>

Lower-case tags
This means no more upper case tags to enhance the presentation of your Web page code.The W3C recommendation points out that this is necessarybecause XML is case-sensitive, and <b> is not the same as <B>.

End-tags
Only those elements that are declared in the DTD (see box) as Empty, can omit the end-tag. All other elements must have end-tags. 

See the correct and incorrect ways of using end tags.

Incorrect:
<p> This is without an end-tag. 

Correct:
<p> This correctly ends with an end-tag </p> 

Attribute values
Not only string values of attributes, but even numeric values must be quoted. 

Correct:
<td colspan=”1”>

Attribute minimization 
XML does not support attribute minimization. 

This means you cannot shrink the attribute-value pair to only have the value in XHTML as is sometimes done in HTML.

Incorrect:
<input checked>

Correct:
<input checked = “checked”>

Close empty elements
Empty elements like <br>, <hr>, <img> etc. 

must either have an end tag, or the start tag must end with a / >. 

For example <br/> or <hr> </hr>

To ease the transition from HTML to XML-based XHTML, XHTML has been kept backwards-compatible with HTML.

That is, you will need to adhere to syntax, but your XHTML pages will not have any problems with current or older browsers.

For backward compatibility with HTML4.0, the following is recommended by W3C.

  • Include a space before the trailing / and > of empty elements, for example, <br />, <hr /> and <img src=”karen.jpg” alt=”Karen” />. 
  • Use the minimized tag syntax for empty elements, for example, <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

id replaces name
XHTML1.0 has deprecated the use of name attribute of the a, applet, form, frame, iframe, img, and map elements, and it will be removed from XHTML in subsequent versions. In place of name, you should use id. 

For example, <a id=”foo” name=”foo”>…</a>.

A simple example is listed below.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” 
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<head>
<title>Testing XHTML</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1” />
</head>
<body>
<p>Hello World!</p>
<p>
<a href=”http://validator.w3.org/check/referer”><img src=”http://www.w3.org/Icons/valid-xhtml10”
alt=”Valid XHTML 1.0!” height=”31” width=”88” /></a>
</p>
</body>
</html>

Let us now delve into a small example and put up a W3C compliant test XHTML page. 

Note that this page will not get validated, if it’s on your local hard disk. Host it on some website, or try the Local-page utility at
http://validator.w3.org/

The point to note is that an XHTML page has three main parts: DOCTYPE, HEAD and BODY.

DOCTYPE points to the DTD (Document Type Definition) to be used to validate the XHTML page. It is mandatory to start an XHTML document with the DOCTYPE tag.

There are three DTDs used with XHTML.

Strict: Used in conjunction with external style sheets and scripts. Your XHTML document will contain only clean markup, no presentation tags. 

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

Transitional: Used when you want to use the presentation features of HTML. 

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

Frameset: Used when you want to take advantage of frames. 

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

The HEAD and BODY parts of the XHTML document are just like HTML4.0 HEAD and BODY, except that you will have to take care of XHTML syntax. (Hence, write <head> … </head> and <body> … </body> in lowercase, for starters!)

What next
XHTML1.0 is meant to serve as a transition from HTML 4.0 to XML. XHTML1.1 supports modularity and is closer to XML and XHTML2.0 is still in its third draft, and a stable release is awaited. So, as a Web developer, should you consider switching to XHTML? Since a lot of effort will go into fixing your ‘working’ HTML4.0 pages, you have to make this choice depending on whether or not there are possibilities for your website(s) to be viewed through user-agents other than Web browsers on desktops. 

But, given the size of the Internet and the general trend towards Web access through non-traditional means, it might be a good idea to give this a thought. 

Shruti Pareek

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

<