HTML is a very succesful language, a large proportion of the web is written with it,
but it has came to a point where further development becomes difficult. The problem
with HTML is that it´s lousily typed, so to show it on a browser, the code of the browser
needs to be more powerful to be able to show the page properly. This represents a
problem to all the portable devices like handheld pc´s which have far less processing
power, not being able to show HTML pages. To solve this the W3Consortium developed
the XHTML standard.
XHTML means Extensible Hypertext Markup Language. If you alredy know HMTL, then
XHTML will be easy for you. You have to remember a few things to code your pages on XHTML:
- Tag and attribute names must be written in lowercase:
In HMTL you can write your tags either in lowercase or uppercase,
and even combine both on the same document.
<CENTER><H1>This is centered text</H1></CENTER>
In XHTML you have to write all tags and attribute names in lowercase
<center><h1>This is centered text</h1></center>
Elements must be nested properlyIn HTML it was posible to nest in this way:
<i>This is <b>some text</i></b>
In XHTML you have to next the elements in the proper order
<i>This is <b>some text</b></i>
All elements have to be closedSome HTML elements like paragraph didn´t need to be closed on HTML
<p> This is a paragraph
<p> This is another paragraph
In XHTML you have to close all elements
<p> This is a XHTML paragraph </p>
<p> This is another XHTML paragraph </p>
There are some elements in HMTL that do not have a closing tag,
those elements are called empty elements. Empty elements also need
to be closed. To close them you add a forward slash / before the end bracket >.
To keep compatibility with current browsers you have to left a space
between the element text and the forward slash. In HTML we have:
This line ends with a break <br>
<img src="myimage.jpg">
And in XHTML
This line ends with a break <br />
<img src="myimage.jpg" />
All attribute values must be quoted and cannot be minimizedIn HTML we have this
<ul compact>
In XHTML you have to make it like this
<ul compact="compact">
The name atribute is replaced with idIn HTML some tags elements (a, applet, frame, iframe, img, and map) have a name attibute,
<img src="mypicture.jpg" name="mypicture"/>
In XHTML you need to change that for the id attribute
<img src="mypicture.jpg" id="mypicture" />
For the code to be compatible with current browsers you have to use both attributes
<img src="mypicture.jpg" id="mypicture" name="mypicture" />
Mandatory elementsIn XHTML is mandatory to include the following elements: html, head, body and title.
The
DOCTYPE declaration is also mandatory.There are three valid XHTML document types
This declaration is used when you want to use CSS.
You have to use this DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This declaration is used when you want to support browsers that can´t use CSS.
You have to use this DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This declaration is used when you want to use frames on your pages.
You have to use this DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Conclusion
As you can see is very easy to change your current page to be XHTML compliant.