Home > Articles > Web Development > HTML/CSS

  • Print
  • + Share This
This chapter is from the book

Terminate Each Entity Reference

Place semicolons after entity references.

&copy 2007 TIC Corp.
if (i &lt 7) {  
Ben &amp Jerry's Ice Cream  
  • arrow2.jpg
© 2007 TIC Corp.   
if (i < 7) { 
Ben & Jerry's Ice Cream 


XML requires that each entity reference end with a semicolon.

Web browsers can usually work around a missing semicolon, but only if the entity name is followed by whitespace. For instance, most browsers can handle "Ben &amp Jerry's" but not "A&ampP".

Potential Trade-offs

None. All browsers recognize entity references that end with semicolons.


To find cases such as this, search for any entity reference where whitespace precedes the next semicolon:


Because the next character after the entity reference is unpredictable, you're better off replacing it manually or letting Tidy or TagSoup do the work. They can both fix most of these problems.

This search will also find a number of purely unescaped ampersands. This is especially common in two places: JavaScript and URLs.

Validation should find any remaining cases, and you can fix those by hand. Sometimes manual inspection is necessary to see exactly where the entity boundary lies.

  • + Share This
  • 🔖 Save To Your Account