Convert HTML to XHTML – attributes

All XHTML attributes must be quoted.

In HTML you don’t have to use quotes ie


<table width=100%>

However in XHTML all attributes must be enclosed by quotes ie


<table width="100%">

XHTML atributes cannot be shortened.

With HTML you can shorten a few of the attributes to save time typing them out in long hand. If you do this in XHTML it will causes incompatibilities between browsers and other devices.

An example of a commonly shortened tag is:


<input type="checkbox" value="yes" name="agree" checked>

In this, it is the checked part which is incorrect. In XHTML all shortened attributes must be written in their ‘long’ format. For example:


checked="checked"

so the checkbox code shown above would now be written as:


<input type="checkbox" value="yes" name="agree" checked="checked">

The ID Attribute

The largest change from HTML to XHTML is the one tag attribute change.

In HTML, the <img> tag has an attribute ‘name’. This is usually used to refer to the image in javascript for doing actions like image rollovers. This attribute has now been changed to the ‘id’ attribute.

So, the HTML code:


<img src="myimage.gif" name="my_image">

would need to be written in XHTML as:


<img src="myimage.gif" id="my_image" />

Of course, this would not be backward compatible with older browsers, so if you still want your site to work fully in all old browsers
(as XHTML is intended to do), you will need to include both id and name attributes (this would also be correct XHTML):


<img src="myimage.gif" id="my_image" name="my_image" />

Speak Your Mind

*