Now that we have an understanding of the background of XHTML let's talk about some of the
differences between XHTML and HTML.
- XHTML tags and attributes must be in lower case.
- All tags must be closed.
- <head> and <body> tags can't be left out.
- All attribute values must have quotation marks.
- A DTD declaration must be included at the top of the document.
- <!DOCTYPE PUBLIC "-//W3C/DTD XHTML 1.0 STRICT//EN" "">
- A reference to the XML namespace needs to be in the <html> element.
- <html xmlns=http://www.w3.org/tr/xhtml1>
- Tags must be properly nested.
- The <title> element must be the first element in the head.
- Attributes cannot be shortened or "minimized".
So what does XHTML do for us? By combining the HTML and XML we have the tags and
elements of HTML and the language of XML. We now have web pages that can be read by
all XML enabled devices.
If by now you're not totally convinced that XHTML is the way to go, picture the
following. Suppose I opened up my previous example in Netscape or even an earlier
version of Internet Explorer (yes, there are people like that still out there…).
I’d bet money on the fact that it wouldn’t look the same. It will take at least a
couple of years for more than half the world to upgrade to XML supported browsers.
We can't wait that long, and now we don’t have to. XHTML lets me write well-formed
documents now that are cross-browser and "backward" browser compatible.
Think about that!
If I were to re-write my example above in XHTML it would like this:
<?xml version="1.0" encoding="UTF-9"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" lang="eng">
<head>
<title>Good XHTML</title>
</head>
<body>
<h1>Good XHTML example</h1>
</body>
</html>
I'm not going to show you the results in IE. Your homework assignment for this
article is to take this example and view it in IE and Netscape. Are you convinced yet?
This should provide you with a nice overview of XHTML. In my next article, we'll
cover some practical examples of XHTML, what we can do with it and we will be putting
it to work.