Common mistakes that lead to invalid XHTML

published Feb 17, 2006, last modified Jun 26, 2013

When writing HTML by hand, these are the most common mistakes that lead to invalid HTML or XHTML:

Have a WordPress blog? Having trouble with Section 508 and validation? Get the WordPress XHTML validator, and forget about validation issues!

Forgetting to terminate entities

The & character is reserved in HTML and XHTML. You can't just place it on your code and expect it to be valid.

The & character is used to post entities in content. Entities represent special characters, such as í (that would be í). When writing an entity by hand, a common mistake is to forget the trailing semicolon. That unterminated entity is shown as a series of errors in the W3C Validator.

And how do you put a literal ampersand? Use &.

Ampersands in URLs

This is actually a variant of the former error. Basically, even if it's text on an URL (for example, in an href attribute on an a tag), you can't just put an ampersand there. You need to use the proper form (see above)

Neglecting to properly close a tag

In XHTML, some tags, like
, need to be closed inline. The tag should be written like this:
.

Overlapping and context-sensitive tags

Some tags cannot go within others. For example, it is an error to include a

tag within another

tag. It is also illegal to start an tag, then place any block-level tag (such as

) within it. Another common mistake is closing a tag before its children tags have been closed.

Watch out for errors, and validate your pages often! So long, folks!