HTML Character Entities

HTML

HTML Character Entities

.

There are some characters in HTML that have a special meaning to an HTML document and can't be used as text. For example we use < and > to start and end HTML tags. When we use these characters we run into the problem we see below.

This HTML Code Produces This
<This will not display>  

The browser is expecting an HTML tag to be within the < and >. Since the browser does not display what is contained between < and > nothing is displayed.

At the same time you are noticing that we have been able to display < and > in the sentences describing how we can have issues with < and >. We have used character entities to display < and > in the HTML source code.

The character entity for < is &lt; or &#60;
For > is &gt; or &#62;

A character entity has three parts: an ampersand (&), an entity name ( lt or gt in our case) or a # and an entity number ( 60 or 62 in our example) and finally a semicolon (;).

Another issue is spacing of text. For example;

This HTML Code Produces This
This    is 4 spaces apart This is 4 spaces apart

In our text editor we wrote "This" and then we added 4 spaces before writing "is 4 spaces apart". However, you will notice that when the HTML is shown in the brower there is only one space between "This" and "is". The reason is that HTML generally cuts down or truncates spaces to one space.

To get around this we use the non-breaking space entity &nbsp;

This HTML Code Produces This
This&nbsp;&nbsp;&nbsp;&nbsp;is 4 spaces apart This    is 4 spaces apart

Here are some more commonly used character entities.

Result Description Entity Name Entity Number
  non-breaking space &nbsp; &#160;
< less than &lt; &#60;
> greater than &gt; &#62;
& ampersand &amp; &#38;
" quotation mark &quot; &#34;
¢ cent &cent; &#162;
£ pound &pound; &#163;
¥ yen &yen; &#165;
euro &euro; &#8364;
§ section &sect; &#167;
© copyright &copy; &#169;
® registered trademark &reg; &#174;
× multiplication &times; &#215;
÷ division &divide; &#247;

.

Home | About | Contact Us | Sitemap

HTML