Conversion From HTML to XHTML
Written
Author
This is probably going to be the most viewed page of my XHTML section. It shows how to convert your current pages from HTML into XHTML. A lot of the information is the same between the two types of coding and many of the differences you may have already started doing.
In HTML, there are many tags that may be omitted and still be considered as good coding. These include some ending tags of a set (such as the td tag) or foundation ones (such as the head and body tags). XHTML will not allow this. All main foundation tags and all closing tags must be included.
Tag and property names must be written in lowercase letters. Since XML is case-sensitive, XHTML tag and property names must be written in lowercase. Property values may still be any case you want.
wrong:
correct:
All tags must nest properly, no overlapping. Some browsers don't care if you overlap elements even though it is considered bad HTML coding. With XML and XHTML, you need to close the tags in reverse order. (last opened = first closed)
wrong:
correct:
All tags, including empty tags) must have a termination or ending tag. Regular tags such as the P or LI tag are commonly used on their own without an ending tag. XML and XHTML must include the ending tags for all of the tag sets. Empty elements (those without a closing tag) have no content.
Empty tags are the special single tags such as br, hr, img, link and meta. Since these do not come as a set, a termination must be specified within the tag itself. This is done by entering a space and forward slash into the tag. Examples:
Technically, there isn't supposed to be a space before the forward slash, but it is needed for todays browsers to recognize it. The space is supported by the W3C standards for conformance.
Other tags affected by this are: area, base, frame, input, and option.
Property values must be quoted. If you follow good HTML coding practice, then you are probably already doing this. Every value must be quoted, even if it's numeric.
wrong:
correct:
(Notice the use of the termination in the correct example too)
Tag properties cannot be minimized. There are some tag properties that are stated as a single word without a value assigned to them. XHTML requires that each property must have a quoted value assigned to it. Examples:
wrong:
correct:
For any pages using a nested list area, the inside list must be contained within a LIne tag set.
Notice the use of the ending LI tags as well.
For any style or script areas (that is CSS and JavaScript), take out the comment tags surrounding the scripts. These comment tags are usually entered before and after the script/styles to hide them from older browsers. Considering most people have a browser version 4 or higher these days, these aren't necessary anyways. The W3C actually recommends using external styles/scripts if possible instead of having them embedded.