Avoid These Common XHTML Errors

Written by Karen | Friday, August 18th, 2006
, , , ,

Many visitors to my site have downloaded my XHTML templates and then email me to show me how they are using my work.

Some are less-experienced coders or do not really know how XHTML differs from HTML.

Here are the most common errors I’ve come across:

  1. Not closing empty elements
    • Wrong: <br>
    • Right: <br />
  2. Not closing non-empty elements
    • Wrong: <p>This is a paragraph.<p> This is another paragraph.
    • Right: <p>This is a paragraph.</p> <p>This is a second paragraph.</p>
  3. Improperly nesting elements
    • Wrong: <em><strong>This is random text.</em></strong>
    • Right: <em><strong>This is random text.</strong></em>
  4. Nesting block-level elements within inline elements
    • Wrong: <em> <h2>About Us</h2></em>
    • Right: <h2><em>About Us</em></h2>
  5. No alternate text for images (using the alt attribute, which helps make pages accessible for devices that do not load images or screen-readers for the blind)
    • Wrong: <img xsrc="images/logo.jpg" />
    • Right: <img xsrc="/images/logo.jpg"
      alt="Company Logo" />
  6. Not putting quotation marks around attribute values
    • Wrong: <td colspan=2>
    • Right: <td colspan="2">
  7. Using the ampersand outside of entities (use &amp; to display the ampersand character)
    • Wrong: <title>Love & Marriage</title>
    • Right: <title>Love &amp; Marriage</title>
  8. Using uppercase tag names and/or tag attributes
    • Wrong: <BODY><P>My Web Site</P></BODY>
    • Correct: <body><p>My Web Site</p></body>

By making sure you don’t make the above mistakes, you are well on your way to having an XHTML website that will validate.

Related Posts