HTML
HTML introduction
HTML basics
HTML text format 1
HTML text format 2
HTML text format 3
HTML links
HTML images
HTML image maps
HTML forms
Fieldset/legend tags
Email links
HTML labels
HTML tables
HTML frames
HTML backgrounds
HTML colors
HTML color shades
HTML color usage
HTML marquees
HTML fonts
HTML entities
HTML stylesheets
HTML layout
HTML div/span
HTML audio
HTML video
HTML objects
HTML d'load media
HTML meta tags
HTML scripts
HTML declarations
HTML head section
HTML document types
HTML tag rules
HTML things to avoid
URL formatting
Encoding and decoding
HTML use/access
HTML publish work
History of HTML
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML entities

There is so much text on so many webpages across the web, and some of this text happens to be special characters that do not appear on a keyboard. How then, to go about including such characters on webpages?

This lesson focuses on:

What is an entity?

An entity is a special code that will display certain characters on webpages. With entities you can display things like the copyright symbol ( © ), the trademark symbol (), the ampersand symbol (&), and more.

Entity construction

Now that you what entities are, how do you go about using them?

An HTML character entity has three parts:

For example, to display a greater than sign on a webpage, we would write > or >

Here is a greater than sign - &gt; <br /> Here it is again - &#62;

Output:

Here is a greater than sign - > Here it is again - >

NOTE: While you can use names or numbers for character entities, it is better to use names because they are easier to remember than numbers.

NOTE: Entities are case sensitive!

Common entities

There are many entities you can use, and within the set of available entities, there is a set of very commonly used entities.

Common character entities and what they will display:

Common entities
Entity Name Entity Number Character Output
&nbsp; &#160; space  
&lt; &#60; less than sign <
&gt; &#62; greater than sign >
&amp; &#38; ampersand &
&quot; &#34; quotation mark "
&apos; &#34; apostrophe '
&copy; &#169; copyright symbol ©
&reg; &#174; trademark symbol ®
&times; &#215; multiplication symbol x
&divide; &#247; division symbol ÷

Example using some of the common entities:

<html> <head> <title>Character entities</title> </head> <body> HTML tags: <br /><br /> &lt;p&gt;, &lt;h1&gt;, &lt;a&gt;, &lt;table&gt;, &lt;body&gt; <br /><br /> With character entities, you can also create lots of &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;spaces <br /><br /> This page is copyright &copy; &amp; trademark &trade; <br /><br /> 5 &times; 5 = 25 <br /><br /> We&apos;re just hangin&apos; out on a saturday afternoon </body> </html>

Output:

HTML tags: <p>, <h1>, <a>, <table>, <body> With character entities, you can also create lots of        spaces This page is copyright © & trademark ™ 5 × 5 = 25 We're just hangin' out on a saturday afternoon

For a full list of HTML character entities, read our HTML character entities reference page.

Read more about text formatting in our HTML text formatting 1, HTML text formatting 2, and HTML text formatting 3 lessons.

Reverse entities

What if you wanted to print the code for an entity on a webpage instead of the character itself?

Remember that every entity begins with the & symbol, and how do we display this symbol? By using the &amp; entity. So to display the code for an entity on a webpage instead of the character itself, simply use &amp; to produce an & symbol followed by the rest of the entity code.

Example:

Entity code for the < (less than symbol) - &amp;lt; <br /> Entity code for the > (greater than symbol) - &amp;gt;

Output:

Entity code for the < (less than symbol) - &lt; Entity code for the > (greater than symbol) - &gt;

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments