Incorporating XHTML
Part 2, the Specification
By Tyler Downer
2/16/08
After last week's article, you may be wondering what the actual differences between HTML and XHTMl are. This week will cover what is different and next week will present a sample web page that I will show to convert an old HTML web page into XHTML.
Because XHTML is based upon HTML, it is very similar and easy for someone who used to it to learn. The main differences between them are:
- You should have an XML namespace at the beginning of your page. A namespace looks like this:
<?xml version="1.0"?>. However, this can cause problems in some browsers and is not required. - You must declare an XHTML DOCTYPE before the HTML element. Here is a list of valid DOCTYPES. I will explain each one in detail later.
- After the DOCTYPE, the HTML element is now typed like this:
<html xmlns="http://www.w3.org/1999/xhtml">. This shows that the default language is XHTML. - You must properly nest and close elements. For example
<p><strong>some text</p></strong>is not correct, but<p><strong>some text</strong></p>is. - All XHTML must be in lowercase.
<strong>is acceptable, but<STRONG>is not. - You must quote all attribute with either " or ', but do not mix them. For example,
<img src="image.jpg">OR<img src='image.jpg'>. - All elements, empty or non-empty, must be close. Like
<p></p>or<img src="image.jpg" />. - You must fully declare attributes and use
idand notnameto identity elements.
Most of the above requirements are easy to understand, but what is a DOCTYPE? For those of you who clicked the link in item 2, you saw a window with 2 strange blocks of code. The DOCTYPE was introduced in HTML 4.01, but many web developers did not use it, just as they did not code HTML properly in other ways. To create a compliant XHTML document, you need the DOCTYPE and you have two flavors to choose from.
Strict: This does not allow you to use any deprecated elements. In other words, elements that are not included in XHTML.
Transitional: The most popular DOCTYPE, this allows you to use elements from HTML 4.01, like the font tag. This should only be used while preparing to make a full jump to XHTML.
Along with these DOCTYPEs there is also the Frameset. This allows you to use frames in your document. But frames are such a poor design choice that it is best to stay as far away as possible from them.
There you go, the basic requirements in the XHTML specification. Next week we will look at a typical HTML page and clean it up with XHTML.
Enter our new Contest today!

