XHTML in a Nutshell
- What is XHTML?
- Rules, Rules, Rules
- Ditch the deprecated tags
XHTML in a Nutshell
Page 1
What is XHTML?
XHTML is the natural successor to HTML, an XML-friendly markup language for hypertext. It is a reformulation of HTML as an application of XML. It provides a bridge for web developers in moving from HTML to XML.
If SGML is the granddaddy, then daddy HTML and mommy XML had a baby, and while XHTML may look like its father, it still has to obey momma's rules. The basic differences when transitioning from HTML to XHTML are fairly straightforward.
- Documents must begin with the proper DOCTYPE and Namespace
- All tags - even empty tags - must be closed
- Attributes cannot be minimized
- All tags must be rendered in lower case
- All attribute values must be enclosed in quotation marks
- All tags must be properly nested
- Name is replaced with ID
And that's the basics. We'll get back into details momentarily, but first, let's take a look at another question.
Why use XHTML?
XML is the future of the web. Being a more structured language, XHTML is much easier to parse than is HTML, and so many devices (wireless browsers, Braille readers, etc...) will read web pages correctly only if they're written in XHTML. As HTML pages become less common, browsers will eventually drop support for the older, more difficult to read code, making for a leaner and meaner browser.
Because of XHTML's obsession with being well-formed, we're also moving towards a world where either your pages work exactly as you want, or they break. This is done via page validation.
Page Validation
Page validation is how you check to see if your page is broken. Visit validator.w3.org and enter the URL of the page you want checked. Once the check is complete, either you'll see a nice blue bar telling you that your XHTML is valid, or you'll get the ugly red bar of pain, indicating that you've still got some fixin' to do.
If the latter is the case, the validator lists the errors item by item. You may find that just one mistake actually causes multiple validation errors, so the 142 errors on your page might actually be fixed with only 26 corrections. It's amazing what chaos not closing a div tag can cause.