XHTML: Common Validation Errors

Posted on Thursday, October 2nd, 2008 at 1:16 pm in

Unescaped Ampersand ("&")

Example:
<a href="foo.cgi?chapter=1&section=2">...</a>

Possible Validator Report: Unknown entity…

Solution: Always use &amp; in place of &.

Correct Syntax:
<a href="foo.cgi?chapter=1&amp;section=2">...</a>

Incorrect Nesting of Elements

Example:
<strong><em>...</strong></em>

Possible Validator Report: Missing </em> tag

Solution: Elements in XHTML must be closed in the reverse order that they were opened in.

Correct Syntax:
<strong><em>...</em></strong>

Lowercase DOCTYPE

Example:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd" >

Possible Validator Report: Missing DOCTYPE

Solution: The DOCTYPE is case-sensitive so use the correct case.

Correct Syntax::

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >

Missing closing " /"

Example:
<img src="image.gif" width="100" height="100" alt="Logo">

Possible Validator Report: Missing closing tag

Solution: So-called "empty elements", such as img,
require a trailing space followed by a "/".

Correct Syntax::
<img src="image.gif" width="100" height="100" alt="Logo" />

Upper case tags

Example:
<STRONG><EM>...</EM></STRONG>

Possible Validator Report: There is no such element…

Solution: Use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive e.g. <em> and <EM> are different tags.

Correct Syntax::
<strong><em>...</em></strong>

Unquoted attribute values

Example:
<td rowspan=3>

Possible Validator Report: Missing " "

Solution: All attribute values must be quoted, even those which appear to be numeric.

Correct Syntax::
<td rowspan="3">

You might also be interested in
Tags:

WordPress Installation and Set Up

Top