HTML Entities


Lesson 48 of 58

Some characters have special meaning in HTML. The browser might get confused if you use them directly. So we use character entities instead. These are special codes that tell the browser to show the symbol.


What Are HTML Entities?

Characters like < (less than) and > (greater than) are used to write HTML tags. If you want to show these characters on your page, you need to use their entity codes.

There are two types of entity codes:

  • Entity names – Like &lt; (easier to remember)
  • Entity numbers – Like &#60; (works everywhere)
Basic Entity Example

Without entities, the browser would interpret <p> as a real HTML tag. That would break your page. Entities let you show the characters safely.


The Non-Breaking Space (&nbsp;)

The non-breaking space (&nbsp;) is one of the most used HTML entities. It does two things:

  • It adds a space that will NOT break into a new line (words stick together)
  • It lets you add multiple spaces (browsers normally collapse multiple spaces into one)
Non-Breaking Space Example

In the example above, the first paragraph shows how browsers collapse multiple normal spaces. The second paragraph uses &nbsp; to keep all 10 spaces. The third paragraph shows how words stick together and do not break at the end of a line.


Common HTML Entities

Here are the most useful HTML entities you will use regularly:

Result Description Entity Name Entity Number
  Non-breaking space &nbsp; &#160;
< Less than &lt; &#60;
> Greater than &gt; &#62;
& Ampersand &amp; &#38;
" Double quotation mark &quot; &#34;
' Single quotation mark (apostrophe) &apos; &#39;
¢ Cent &cent; &#162;
£ Pound &pound; &#163;
¥ Yen &yen; &#165;
Euro &euro; &#8364;
© Copyright &copy; &#169;
® Registered trademark &reg; &#174;
Trademark &trade; &#8482;
Note: Entity names are case sensitive. &copy; works, but &COPY; does not.

Using Entities in Practice

Here is a practical example showing how to use entities in a real webpage:

Practical Entity Example

Notice the copyright symbol, the euro and pound signs, and how the <code> text shows as plain text, not as an actual HTML tag.


Entities for Mathematical Symbols

HTML also has entities for mathematical symbols:

Result Description Entity Name
For all &forall;
Partial differential &part;
There exists &exist;
Empty set &empty;
Nabla &nabla;
Element of &isin;
Not an element of &notin;
Contains as member &ni;
Product &prod;
Summation &sum;

Combining Diacritical Marks (Accents)

You can add accents and other marks to letters using combining diacritical marks. These are special codes that combine with the letter before them.

Mark Character Construct Result
` (grave) a a&#768;
´ (acute) a a&#769;
^ (circumflex) a a&#770;
~ (tilde) a a&#771;
` (grave) O O&#768;
´ (acute) O O&#769;
^ (circumflex) O O&#770;
~ (tilde) O O&#771;
Accents Example

Quick Summary

  • Use HTML entities to display reserved characters like < and >
  • Entity names like &lt; are easier to remember than numbers like &#60;
  • The non-breaking space (&nbsp;) prevents line breaks and adds multiple spaces
  • Use &copy; for copyright symbol ©
  • Use &euro; for euro €, &pound; for £, &yen; for ¥
  • Use &lt; for <, &gt; for >, &amp; for &
  • Entity names are case sensitive
  • You can use combining diacritical marks to add accents to letters

What Just Happened? Let Me Explain

  • HTML entities are essential when you write code examples or show special symbols.
  • Without entities, the browser would try to interpret your symbols as HTML code.
  • The non-breaking space is very useful for formatting. It is the only way to add multiple spaces in a row.
  • Always use entities for user-generated content. If someone types HTML tags in a comment, they should be converted to entities so they do not break your page.
  • There are hundreds of HTML entities. You do not need to memorize them all. Just remember the common ones and search for others when you need them.
Tip: In VS Code, you can type HTML entities directly. Many editors have autocomplete for common entities. For example, type “&copy” and it will autocomplete to “&copy;”.

HTML Entities Reference

Here are the most commonly used HTML entities:

Result Entity Name Entity Number Description
  &nbsp; &#160; Non-breaking space
< &lt; &#60; Less than
> &gt; &#62; Greater than
& &amp; &#38; Ampersand
" &quot; &#34; Double quotation mark
' &apos; &#39; Single quotation mark
¢ &cent; &#162; Cent sign
£ &pound; &#163; Pound sign
¥ &yen; &#165; Yen sign
&euro; &#8364; Euro sign
© &copy; &#169; Copyright
® &reg; &#174; Registered trademark
&trade; &#8482; Trademark

Lesson 48 of 58