O'Reilly logo

Web Design in a Nutshell, 2nd Edition by Jennifer Niederst Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Well-Formed XHTML

Web browsers are forgiving of sloppy HTML, but XHTML (being an XML application) requires fastidious attention to every detail. These requirements were outlined briefly in the XML chapter (Chapter 30), but we’ll go over them in this section as they relate specifically to XHTML.

All-Lowercase Element Names

In XML, all tags and attributes are case-sensitive, which means that <img>, <Img>, and <IMG> are parsed as different elements. In the reformulation of HTML into XHTML, all elements were interpreted to be lowercase. When writing XHTML documents (and their associated style sheets), be sure that all tags and attributes are written in lowercase.

If you want to convert the upper- and mixed-case tags in an existing HTML file to well-formed, all-lowercase tags, try the Tidy utility (mentioned previously) or Barebones Software BBEdit (Macintosh only), which can automate the process.

Quoted Attribute Values

XHTML requires that all attribute values be contained in double quotation marks. So where previously it was okay to omit the quotes around single words and numeric values, now you need to be careful that every value is quoted.

End Tags

In HTML, it is okay to omit the end tags for many block elements (such as <p> and <li>) because the browser is smart enough to close a block element when the next one begins. Not so in XHTML. In order to be well-formed, every container element must have its end tag, or it registers as an error and renders the document noncompliant.

Empty ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required