Advertisment

XHTML: New-age HTML

author-image
PCQ Bureau
New Update

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. 

Advertisment

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.

Advertisment

Well-formed documents



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

Incorrect:



This is wrong

Correct:



This is correct

Advertisment

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 is not the same as .

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.

Advertisment

Incorrect:



This is without an end-tag. 

Correct:



This correctly ends with an end-tag

 

Advertisment

Attribute values



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

Correct:



Attribute minimization 



XML does not support attribute minimization. 

Advertisment

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

Incorrect:





Correct:





Advertisment

Close empty elements



Empty elements like

,


, etc. 

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

For example

or


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,

    ,


    and ”Karen”
  • Use the minimized tag syntax for empty elements, for example,

    , as the alternative syntax

    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 simple example is listed below.



http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>









Testing XHTML















Hello World!









alt=”Valid XHTML 1.0!” height=”31” width=”88” />










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. 



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. 



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. 



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 … and … 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

Advertisment