Skip to content

HTML Entities

Certain characters have special meaning in HTML (like < which starts a tag). To display these characters literally as text content, you must use character entities.

Entities are also used to display characters not easily typed on a standard keyboard (like © or €).

An HTML entity is a piece of text (a string) that begins with an ampersand (&) and ends with a semicolon (;). Entities represent specific characters.

There are two types:

  • Named Entities: Use a memorable name (e.g., &lt; for <, &amp; for &, &copy; for ©). Easier to read and remember.
  • Numeric Entities: Use a number corresponding to the character’s code point in Unicode (e.g., &#60; for <, &#38; for &, &#169; for ©). Universally supported by browsers.

Syntax:

&entity_name;
<!-- or -->
&#entity_number;

For example, to display <p> literally in your text, you must write &lt;p&gt; or &#60;p&#62;.

Tip: While named entities are often preferred for readability, numeric entities guarantee display even if a browser doesn’t recognize a specific name (though this is rare for common entities).

You must use entities for these characters when you want them to appear as literal text, not be interpreted as HTML markup:

CharacterDescriptionNamed EntityNumeric Entity
<Less than&lt;&#60;
>Greater than&gt;&#62;
&Ampersand&amp;&#38;
”Double quote&quot;&#34; (Useful inside attribute values quoted with ”)
‘Single quote (apostrophe)&apos;&#39; (Useful inside attribute values quoted with ’)

Example:

<p>The formula is: E = mc&lt;sup&gt;2&lt;/sup&gt;.</p>
<p>Tom &amp; Jerry is a classic cartoon.</p>
<p>He said, &quot;Use entities!&quot;</p>

Browsers collapse multiple consecutive whitespace characters (spaces, tabs, newlines) in HTML source code into a single space when rendering.

To insert an explicit space that browsers won’t collapse, or to prevent a line break between two words, use the non-breaking space entity: &nbsp; (or &#160;).

Example: Keep ‘10 km’ together on one line.

<p>The distance is 10&nbsp;km.</p>

Use &nbsp; sparingly; CSS margin and padding are the standard ways to control spacing.

ResultDescriptionNamed EntityNumeric Entity
©Copyright&copy;&#169;
®Registered Trademark&reg;&#174;
™Trademark&trade;&#8482;
€Euro&euro;&#8364;
£Pound Sterling&pound;&#163;
¥Yen&yen;&#165;
¢Cent&cent;&#162;
•Bullet&bull;&#8226;
—Em dash&mdash;&#8212;
–En dash&ndash;&#8211;

Note: Entity names are case-sensitive (&nbsp; works, &NBSP; does not).

Modern web pages should always use UTF-8 character encoding, declared via <meta charset="UTF-8"> in the <head>. UTF-8 supports virtually all characters used in any language.

With UTF-8, you can often type characters like ©, €, £, or accented letters directly into your HTML source code, and they will display correctly without needing entities.

Example (with UTF-8):

<p>Price: €50. Copyright © 2024.</p>
<p>¡Hola, señor!</p>

However, you still must use entities for the reserved characters <, >, and & to avoid breaking your HTML structure. Using entities for other special characters (&copy;, &euro;, etc.) remains a valid and sometimes clearer alternative to typing them directly.

For a comprehensive list of HTML entities, refer to resources like the MDN Web Docs.