XHTML 1.0 is a reformulation of HTML 4.0. What this really means is that learning XHTML is basically the same as learning HTML. The main difference is a few simple rules - as XHTML is more strict than standard HTML.
The reality is that HTML is not going away. While there are many advantages to having a very flexible system where tags can be easily added and changed in the DTD, but most Web Developers won't need or want their own tags. Why rewrite the way the <p> tag works, when it's already in the document definition?
Converting an HTML Document
There are a few basic rules you need to apply to convert an HTML 4 document to XHTML.
- Stricter adherence to the HTML specification.
Many browsers are very lax in how they interpret HTML. This leads to incongruities in how the pages are displayed, and XHTML doesn't allow that. The best way to correct this is to use an XHTML validator.
- Write well formed documents.
What this generally means is avoiding overlapping elements. The following nested code is acceptable:
because the <em> tag is opened and closed within the <p> tag. However, this is not allowed:
because the <em> tag overlaps the <p> tag.
- Write tags and attributes in lowercase.
XHTML is a case-sensitive markup language, so
are potentially two different tags.
<LI> and <li>
- End tags are required.
In HTML, some tags which actually contain elements do not require the end tag. The most common of these is the
tag. XHTML requires that the
tag be used. For singleton tags, such as
you should include a trailing slash in the tag itself, e.g.
to get a line break.
- Attributes must be quoted and include values.
What this means is that non-quoted attributes such as
are invalid. And attributes which used to stand alone, must now be written as name="value" pairs. For example
adds the noshade attribute to the <hr/> tag.
<hr noshade="noshade" />
- Do a second validation.
The last step is to validate your XHTML again. This will tell you of any additional problems or issues with your code.