The most common errors found during xhtml validation

| | 2 min read

XHTML Validation serves the purpose of rechecking our site to see if it follows the W3C standards. It not only ensures quality, but also teaches us good coding practices and thereby eases maintenance. Validating one's code before taking it live serves as a sign of good professionalism in a coder's career.

Common errors found during XHTML validation are listed below:

1. Not closing empty tags.
Empty tags are tags that do not contain any content.

Example:
<br />
<hr />
Wrong : <br>
Correct :<br />
Wrong : <hr>
Correct :<hr />

2. Not closing non-empty elements

Example:
Wrong : <p>This is a paragraph.<p>
Right : <p>This is a paragraph.</p>

3. Missing a / on self-closing tags.

Example:
Wrong : <img >
Right : <img />

Other self closing tags include:

<area />
<base />
<br />
<col />
<command />
<embed />
<hr />
<img />
<input />
<keygen />
<link />
<meta />
<param />
<source />
<track />
<wbr />

4. Using Uppercase characters in Markup Tags.

Example:
Wrong : <BODY> </BODY>
Right : <body> </body>

5. Not escaping Special characters.

Example:
Wrong : Using the ampersand character as "&" and the angled brackets as "<".
Right : Use them as "&" and "<" instead.

6. Nesting the block level elements

Example:
Wrong : <em><h2>About Us</h2></em>
Right : <h2><em>About Us</em></h2>

7. No specifying alternate text for images.

Example:
Wrong : <img src="images/image.jpg" />
Right : <img src="image.jpg" alt="Image Logo" />

8. Non inclusion of quotes around attribute values

Example:
Wrong: <td rowspan=2>
Right: <td rowspan="2">

9. Starting a class or ID with a number.
Class, ID or name attributes should not begin with a number but can include them

Example:
Wrong : <ul class="bottomregion" id="4">
Right : <ul class="bottomregion" id="level4">