HTML Entities

Introduction to HTML Entities

If you want to display characters that are reserved in HTML, symbols like mathematical symbols, or character in foreign languages, you will need to to use character entities. For instance, displaying a < or > character by simply typing the character from the keyboard, the markup could be confusing for the HTML interpreter which might interpret the character as the beginning or ending of an HTML tag. Character entities are used to diplay characters that are reserved by the HTML language as well as characters in other languages including mathematical symbols.

In order to display a character entity in HTML you can use a specified name or number to represent the reserved character, like this:

&entityname;

 

   -OR-

 

&#entitynumber;

In order to display the < character you would need to type this:

&lt;

 -OR-

&#160;

Advantage of using an entity name: An entity name is easy to remember.

Disadvantage of using an entity name: Browsers may not support all entity names, but the support for entity numbers is good.

Other Useful Entities

Your Web browser's built-in HTML interpreter ignores whitespace. This means that if you have some text in an HTML document where you tapped on your spacebar several times to seperate the words or characters, the borwser's HTML interpreter will ignore all the space characters but one. THis is where the non-breaking space entity comes in handy. Instead of pressing the spacebar on your keyboard, type &nbsp; for each space that you want to be displayed between words or characters. A non-breaking space is also a space that will not break at the end of a line of text and start a new line. The words seperated by the non-breaking space will "stick" together.

The non-breaking hyphen &#8209; is used to define a hyphen character (-) that does not break to a new line.

Links of Interest