Special Characters (Entities) - HTML

Some special characters must be referenced directly instead of simply typed into the document. Some of these characters cannot be typed on a standard keyboard, such as the trademark symbol (™) or copyright symbol (©); others could cause the HTML client confusion (such as the angle brackets, < and >). Such characters are commonly referred to as “entities.”

Entities are referenced by using a particular code in your documents. This code always begins with an ampersand (&) and ends with a semicolon. Three different ways to specify an entity exist:

  • A mnemonic code (such as copy for the copyright symbol)
  • A cimal value corresponding to the character (such as #169 for a copyright symbol)
  • A hexidecimal value corresponding to the character (such as #xA9 for a copyright symbol)

Note that if you use the decimal or hexadecimal methods of specifying entities, you need to prefix the value with a number sign (#).

The following are all examples of valid entities:

  • &nbsp;—A non-breaking space (see later)
  • &a;lt;—The less-than symbol, or left-angle bracket (<)
  • &amp;—An ampersand (&)
  • &#151;—An em dash (—)

Inappropriate Entity Use
One particular entity, the nonbreaking space, is often used and abused to add white space to HTML documents. For example, to add a larger gap between paragraphs, the following code is often used:

<p>&nbsp;</p>

This code results in a blank paragraph—without the space, most browsers will not render the paragraph because it is empty. However, that is not the intent of this entity—it is meant to keep words from being split between rows of text. Using it to add white space is not recommended. Instead, use styles as directed in the various sections of this book.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HTML Topics