Although XHTML and HTML are very similar since they use the same tags and attributes, XHTML contains many rules that you must follow to ensure compatibility with all browsers and devices. The following explains how to write an XHTML web page so that it complies with the XHTML standards;
Tags must be written in lowercaseAll tags in XHTML including tag name and attributes must be written in lowercase. So the following code is illegal in XHTML;
<B>...bold text...</B>
And must be replaced with;
<b>...bold text...</b>
XHTML requires that all tags use their appropriate ending tags. If a tag does not require an ending tag a '/' must be inserted before the closing >. So to insert an image into an XHTML document, the image tag must be written like so;
<img src="images/picture.jpg" />
It is recommend to insert a space before the '/>' to ensure compatibility with older browsers
All attributes require a valueAll tags in XHTML require a value. The following code can not be used in XHTML;
<input checked>
It must be written as;
<input checked="checked" />
XHTML requires that all attribute values be quoted. The following code;
<img width=100>
Must be replaced with;
<img width="100" />
Some HTML tags that use the name attribute must be replaced with the ID attribute. To help ensure compatibility with older browsers you can use both the name attribute and the ID attribute in the same tag.
Documents must be properly nestedXHTML requires that your documents tags be properly nested. In HTML the following code is legal and will show up correctly in most web browsers;
<B><U>Bold and underlined text</B></U>
However, it is illegal in XHTML and must be written in this way;
<B><U>Bold and underlined text</U></B>
ALL XHTML documents require the proper DOCTYPE declaration. The html head and body tags must be used. The following is the most basic XHTML document;
<!DOCTYPE appropriate doctype> <html> <head><title>Web Page Title</title> </head> <body> ....xhtml content goes here.... </body> </html>