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.
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 & biscuits cost €5. Use < and > when showing angle brackets.</p>
<h2>Markup you can read</h2>
<pre><code><p class="note">Tea &amp; biscuits</p></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 <, > and & 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.
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., < for <, © for ©). Use entity names ( ) or numbers (©) 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 < or <</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:
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 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:
Currency Symbols
Example - Currency Symbols
<p>The price is €50 or £43 or ¥5500</p>
Result:
The price is €50 or £43 or ¥5500
Mathematical Symbols
Example - Math Symbols
<p>5 × 3 = 15</p>
<p>10 ÷ 2 = 5</p>
<p>x ≠ 0</p>
Result:
5 × 3 = 15
10 ÷ 2 = 5
x ≠ 0
Other Common Symbols
Example - Common Symbols
<p>© 2025 My Company</p>
<p>HTML Free Codes®</p>
<p>The temperature is 25°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.
Example - Diacritical Marks
<p>Café is a French word.</p>
<p>He visited España (Spain).</p>
<p>Nü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>à á â ã</p>
Result:
à á â ã
Practical Examples
Example - Displaying HTML Code
<p>To create a heading, use <h1>Your Heading</h1></p>
<p>The <p> tag defines a paragraph.</p>
Example - Legal and Copyright
<footer
>
<p>© 2025 My Company®. All rights reserved.</p>
<p>Product Name™</p>
</footer
>
Example - Scientific Notation
<p>E = mc<sup>2</sup></p>
<p>H<sub>2</sub>O</p>
<p>Temperature range: -10°C to 35°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
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.