HTML Entities

HTML Entities

There are certain ASCII characters that are treated as special characters in an HTML document and can be edited using any text editor.

Many of the keyboards and editors cannot type the non ASCII characters. For this reason the HTML language provides such characters using sequences of 7-bit ASCII characters. These are called character entities and character references.

EXAMPLE

For example the character reference for é is (&#233 ;). The semicolon is mandatory because it is used to terminate the reference. While the entity reference for this character is &eacute ; . The character entities and character references for each character provides the same result for that character as follows:

<p>

&#233 ;

</p>

Resulting in:

p

And,

<p>

&eacute ;

</p>

Resulting in:

eacute

This method of generating characters is used when sending emails because the mails mishandle the 8 bit characters; however, this is not the problem for hypertext servers.

Note that the character reference is started with a “&#” and the entity reference is started with only “&”.

Special Characters

There are characters that have a special meaning in an HTML document for example (<) and (>) are used to denote the markup tags, (&) is used to indicate an entity or character reference, these characters are printed in an HTML document using a special way. If you want these reserved characters to be printed in the document you can use the character reference or character entity. Some of the character references and character entities are shown in the following table:

Character Character reference Entity Reference
Left angle bracket (<) &#60; &al;
Right angle bracket (>) &#62; &gt;
Ampersand sign (&) &#38; &amp;
Double Quotation sign (“) &#34; &quot;
Non breaking space &#160; &nbsp;
¢ &#162; &cent;
£ &#163; &pound;
¬ &#172; &not;
® &#174; &reg;
° &#176; &deg;
´ &#180; &acute;
À &#192; &Agrave;
Á &#193; &Aacute;
&#182; &para;
» &#187; &raquo;
¼ &#188; &frac14;
½ &#189; &frac12;
¾ &#190; &frac34;
¿ &#191; &iquest;
ß &#223; &szlig;

NOTE: The non breaking space has a special affect in an HTML document that is it does not break the line to a new line but generates a space between the lines. Using the non breaking space will increase the readability. Consider the following example to illustrate this:

When Non Breaking Space is not used

EXAMPLE

<p> I WANDERED lonely as a cloud

That floats on high o’er vales and hills,

When all at once I saw a crowd,

A host, of golden daffodils;

Beside the lake, beneath the trees,

Fluttering and dancing in the breeze. </p>

This will result in:

this-will-result-in

When using the Non Breaking Space

EXAMPLE

<p> I WANDERED lonely as a cloud &nbsp ;

That floats on high o’er vales and hills, &nbsp ;

When all at once I saw a crowd, &nbsp ;

A host, of golden daffodils; &nbsp ;

Beside the lake, beneath the trees, &nbsp ;

Fluttering and dancing in the breeze. </p>

This will result in:

this-will-result-in-2

It can be clearly seen that &nbsp generates a specific space that makes the user understand the statements easily.