HTML Entities

Master techniques for rendering protected characters and specialized glyphs within markup content

Complete working example

Entities and escaped HTML code

Display literal angle brackets, an ampersand and an escaped code sample.

HTMLCSSSelf-contained
Edit in playground

Live preview

Original code, no external assets
Read the complete HTML document
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>My code example</title>
<style>
:root {
  font-family: system-ui, sans-serif;
  color: #18223b;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  padding: 24px;
  background: #edf1ff;
  display: grid;
  place-items: center;
}
main {
  min-width: 0;
  width: min(100%, 600px);
  background: white;
  border-radius: 20px;
  padding: clamp(20px, 5vw, 32px);
}
h1 {
  font-size: clamp(24px, 5vw, 32px);
  line-height: 1.2;
  margin: 0 0 16px;
}
h2 {
  font-size: 20px;
  margin: 24px 0 12px;
}
p,
li {
  line-height: 1.65;
}
a {
  color: #2545a8;
  text-underline-offset: 3px;
}
button,
input,
select,
textarea {
  font: inherit;
}
button {
  min-height: 44px;
  border: 1px solid #9eaed0;
  border-radius: 10px;
  padding: 10px 14px;
  background: #eff3ff;
  color: #18223b;
  cursor: pointer;
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #3658bf;
  outline-offset: 3px;
}
pre {
  max-width: 100%;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #eef2fa;
  padding: 16px;
  border-radius: 10px;
}
code {
  font-family: ui-monospace, monospace;
}

</style>
</head>
<body>
<main>
  <h1>Show code as text</h1>
  <p>Tea &amp; biscuits cost €5. Use &lt; and &gt; when showing angle brackets.</p>
  <h2>Markup you can read</h2>
  <pre><code>&lt;p class=&quot;note&quot;&gt;Tea &amp;amp; biscuits&lt;/p&gt;</code></pre>
  <p>The code sample is displayed as text; it does not create another paragraph.</p>
</main>
<script>

</script>
</body>
</html>

How it works

The browser decodes character references such as &lt;, &gt; and &amp; when parsing HTML. A code element gives text semantic meaning; escaping is what stops markup being parsed. UTF-8 can display ordinary Unicode like € directly. The sample uses another level of ampersand escaping to show an entity in the visible code.

Troubleshooting and limits

Do not insert untrusted input as innerHTML. Use textContent for plain text. HTML text escaping is not a substitute for context-specific handling of JavaScript, URLs or CSS. If an entity appears literally, check whether the ampersand was escaped one time too many.

Explore more original working examples.

Quick Answer

What are HTML entities?

HTML entities are special character codes used to display reserved characters (like < > &) and symbols that aren't on keyboards (like © ™ €). They start with & and end with ; (e.g., &lt; for <, &copy; for ©). Use entity names (&nbsp;) or numbers (&#169;) for proper character encoding.

Protected HTML characters require entity substitution for proper display. Additionally, keyboard-unavailable characters become accessible through entity notation systems.

What are HTML Entities?

Some characters are reserved in HTML. If you use the less than (<) or greater than (>) signs in your text, the browser might mix them with tags.

Character entities are used to display reserved characters in HTML.

Entity Syntax

An entity can be written in two ways:

  • Entity Name: &entity_name;
  • Entity Number: &#entity_number;

Example - Displaying Less Than Sign

<p>To display a less than sign, use &lt; or &#60;</p>

Result:

To display a less than sign, use < or <

Tip: Using entity names is easier to remember, but not all browsers support all entity names. However, entity numbers are supported by all browsers.

Non-breaking Space

A commonly used entity in HTML is the non-breaking space: &nbsp;

A non-breaking space is a space that will not break into a new line. Two words separated by a non-breaking space will stick together (not break into a new line).

Example - Non-breaking Space

<p>This is paragraph 1.</p>
<p>This is paragraph&nbsp;2.</p>

Common Uses:

  • Prevent line breaks between words (e.g., "10 km")
  • Add multiple spaces (HTML normally collapses multiple spaces into one)
  • Keep related items together (e.g., "Mr. Smith")

Common HTML Entities

Here are the most commonly used character entities in HTML:

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 &apos; &#39;
¢ cent &cent; &#162;

Currency Symbols

Result Description Entity Name Entity Number
¢ cent &cent; &#162;
£ pound &pound; &#163;
¥ yen &yen; &#165;
€ euro &euro; &#8364;

Example - Currency Symbols

<p>The price is &euro;50 or &pound;43 or &yen;5500</p>

Result:

The price is €50 or £43 or ¥5500

Mathematical Symbols

Result Description Entity Name Entity Number
× multiplication &times; &#215;
÷ division &divide; &#247;
± plus-minus &plusmn; &#177;
≠ not equal &ne; &#8800;
≤ less than or equal to &le; &#8804;
≥ greater than or equal to &ge; &#8805;

Example - Math Symbols

<p>5 &times; 3 = 15</p>
<p>10 &divide; 2 = 5</p>
<p>x &ne; 0</p>

Result:

5 × 3 = 15

10 ÷ 2 = 5

x ≠ 0

Other Common Symbols

Result Description Entity Name Entity Number
© copyright &copy; &#169;
® registered trademark &reg; &#174;
™ trademark &trade; &#8482;
§ section &sect; &#167;
° degree &deg; &#176;
• bullet &bull; &#8226;

Example - Common Symbols

<p>&copy; 2025 My Company</p>
<p>HTML Free Codes&reg;</p>
<p>The temperature is 25&deg;C</p>

Result:

© 2025 My Company

HTML Free Codes®

The temperature is 25°C

Diacritical Marks

Diacritical marks (accents) are added to letters. Some diacritical marks are available as separate entities in HTML.

Mark Character Entity Name Entity Number
acute accent á &aacute; &#225;
grave accent à &agrave; &#224;
circumflex â &acirc; &#226;
tilde ñ &ntilde; &#241;
umlaut ü &uuml; &#252;
cedilla ç &ccedil; &#231;

Example - Diacritical Marks

<p>Caf&eacute; is a French word.</p>
<p>He visited Espa&ntilde;a (Spain).</p>
<p>N&uuml;rnberg is a city in Germany.</p>

Result:

Café is a French word.

He visited España (Spain).

Nürnberg is a city in Germany.

Combining Diacritical Marks

A combining character is a character that is placed on top of another character. These are called combining diacritical marks.

Example - Combining Marks

<p>a&#768; a&#769; a&#770; a&#771;</p>

Result:

à á â ã

Practical Examples

Example - Displaying HTML Code

<p>To create a heading, use &lt;h1&gt;Your Heading&lt;/h1&gt;</p>
<p>The &lt;p&gt; tag defines a paragraph.</p>

Example - Legal and Copyright

<footer
  >
    <p>&copy; 2025 My Company&reg;. All rights reserved.</p>
    <p>Product Name&trade;</p>
</footer
>

Example - Scientific Notation

<p>E = mc<sup>2</sup></p>
<p>H<sub>2</sub>O</p>
<p>Temperature range: -10&deg;C to 35&deg;C</p>

Best Practices for Using Entities

✓ Tips

  • Always use entities for reserved characters (<, >, &, ")
  • Use entities for special characters not on your keyboard
  • Entity names are easier to remember than numbers
  • Entity numbers have better browser support
  • Use UTF-8 charset to support most characters without entities
  • Use &nbsp; to prevent unwanted line breaks
  • Consider using Unicode directly if UTF-8 is enabled

Test Your Knowledge

5 practice questions are available. Choose Start practice to try them.