The Web Design Group

Common Problems

If you think that another common problem deserves discussion here, please let me know.

Writing HTML in a SCRIPT Element

A common error (and the most common source of erroneous bug reports for the WDG HTML Validator) occurs when writing HTML tags within a SCRIPT element:

<script type="text/javascript">
  // This is an error!
// -->

Technically, the first occurrence of "</" followed by any letter is considered the end tag for the SCRIPT element. While browsers are forgiving in this, authors should avoid using strings such as "</P>" in their embedded scripts. JavaScript allows authors to use a backslash to avoid ending the SCRIPT element prematurely:

<script type="text/javascript">
// -->

Ampersands (&'s) in URLs

Another common error occurs when including a URL which contains an ampersand ("&"):

<!-- This is invalid! --> <a href="foo.cgi?chapter=1&section=2">...</a>

This example generates an error for "unknown entity section" because the "&" is assumed to begin an entity. In many cases, browsers will recover safely from the error, but the example used here will cause the link to fail in Netscape 3.x (but not other versions of Netscape) since it will assume that the author intended to write &sect;ion, which is equivalent to §ion.

To avoid problems with both validators and browsers, always use &amp; in place of &:

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

Incorrect Nesting of Elements

Elements in HTML cannot overlap each other. The following is invalid:

<B><I>Incorrect nesting</B></I>

In this example, the B element is intended to contain an I element. To be truly contained within the B element, the I element's end tag must occur before the B element's end tag. The following is valid:

<B><I>Correct nesting</I></B>

Using a NAME attribute with IMG or FORM

This problem is discussed in detail at JavaScript and HTML: possibilities and caveats.

Using all lowercase letters in a DOCTYPE

In a DOCTYPE, the formal public identifier--the quoted string that appears after the PUBLIC keyword--is case sensitive. A common error is to use the following:

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

Here the formal public identifier (FPI) is all lowercase. The validator does not recognize the document as HTML 4.0 Transitional since the expected FPI for HTML 4.0 Transitional uses different case:

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">