Other languages: français
If you think that another common problem deserves discussion here, please let me know.
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:
<!-- // This is an error! document.write("</P>"); // -->
As mentioned in the HTML 4 Recommendation's note about specifying non-HTML data in element content, end tags are recognized within SCRIPT elements, but other kinds of markup--such as start tags and comments--are not. This is an unintuitive quirk of SGML for elements defined to have CDATA content.
<!-- document.write("<\/P>"); // -->
Note that in XHTML, authors must also take care when using start tags within a script element. For details, see the Script and Style elements section of the XHTML 1.0 Recommendation as well as the HTML compatibility guideline for embedded scripts.
Another common error occurs when including a URL which contains an ampersand ("&"):
<!-- This is invalid! -->
This example generates an error for "unknown entity section" because the "&" is assumed to begin an entity reference. Browsers often recover safely from this kind of error, but real problems do occur in some cases. In this example, many browsers correctly convert ©=3 to ©=3, which may cause the link to fail. Since ⟨ is the HTML entity for the left-pointing angle bracket, some browsers also convert &lang=en to 〈=en. And one old browser even finds the entity §, converting §ion=2 to §ion=2.
To avoid problems with both validators and browsers, always use & in place of & when writing URLs in HTML:
Note that replacing & with & is only done when writing the URL in HTML, where "&" is a special character (along with "<" and ">"). When writing the same URL in a plain text email message or in the location bar of your browser, you would use "&" and not "&". With HTML, the browser translates "&" to "&" so the Web server would only see "&" and not "&" in the query string of the request.
Elements in HTML cannot overlap each other. The following is invalid:
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:
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">
If you receive the error "Missing a required sub-element of HEAD", check that you have included the TITLE element in the HEAD. The TITLE element is required in all HTML documents.
In XHTML, unlike HTML, element and attribute names must be all lowercase. For example, onMouseOver is an invalid attribute in XHTML, which requires use of onmouseover instead. Either is fine in HTML.