Common mistakes that lead to invalid XHTML

by Rudd-O published 2006/02/17 01:28:06 GMT+0, last modified 2013-06-26T03:24:28+00:00

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 <br>, need to be closed inline. The tag should be written like this: <br/>.

Overlapping and context-sensitive tags

Some tags cannot go within others. For example, it is an error to include a <p> tag within another <p> tag. It is also illegal to start an <i> tag, then place any block-level tag (such as <p>) 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!