Aug
18
Avoid These Common XHTML Errors
|
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:
- Not closing empty elements
- Wrong: <br>
- Right: <br />
- 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>
- Improperly nesting elements
- Wrong: <em><strong>This is random text.</em></strong>
- Right: <em><strong>This is random text.</strong></em>
- Nesting block-level elements within inline elements
- Wrong: <em> <h2>About Us</h2></em>
- Right: <h2><em>About Us</em></h2>
- 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" /> - Not putting quotation marks around attribute values
- Wrong: <td colspan=2>
- Right: <td colspan="2">
- Using the ampersand outside of entities (use & to display the ampersand character)
- Wrong: <title>Love & Marriage</title>
- Right: <title>Love & Marriage</title>
- 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.


Download Design