HTML versus XHTML
For our purposes, we can think of XHTML as a strict form of HTML. Since it came into use after many years using HTML, all browsers accept both. HTML is fine for our class, but, if you build a Web site that you expect to be used for many years in the future, the few extra keystrokes to conform to the XHTML standard are worthwhile.
Here are some of the key differences between XHTML and HTML (there are more differences, but these are common ones):
- Element and attribute names must be lowercase
- All elements must be closed (terminated)
- Empty elements must be terminated too
- Attribute values must be in quotation marks
- Always use character entities for special characters
Additionally, you should place the following in the Head section of an XHTML document in order to specify which language and "vocabulary" you are using:
(If you are curious, you can see the codes for languages other than English here).
For a concrete example, here is the same page marked up in HTML and XHTML. They are both rendered exactly the same by the browser, but, if you view the source of each page, you will see that the XHTML version complies with the restrictions listed above.