🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·
🌐 Web (HTML & CSS)

HTML entities

Special characters use entities: &lt; for <, &gt; for >, &amp; for &, &nbsp; for non-breaking space, &copy; for ©. Use them when you need to show the character, not use it as code.

3 min 10 XP Lesson 10 of 26
HTML entities
🌐

Appy Says…

What if you want to display <p> on a web page without the browser treating it as a tag? HTML entities let you display reserved characters as visible text — and add copyright symbols, arrows, and special characters.

📖

What are HTML Entities?

HTML entities are escape codes for characters that have special meaning in HTML, or characters that can't be typed easily. They start with & and end with ;.

  • &lt; → < (would start a tag)
  • &gt; → > (would close a tag)
  • &amp; → & (would start an entity)
  • &nbsp; → non-breaking space (won't line-break)
  • &copy; → © (copyright symbol)
  • &mdash; → — (em dash)
  • Numeric: &#9829; → ♥ (Unicode code point)
🎮

Think of it like escaping special characters in code

In Python, if you want a quote inside a string you write \' — escaping it. HTML entities work the same way: if you want < to appear as text (not open a tag), you escape it as &lt;.

⚙️

How It Works

  • 1. The browser's HTML parser recognises &name; patterns
  • 2. It replaces them with the corresponding Unicode character before rendering
  • 3. Reserved chars (< > & ") MUST be escaped in page content
  • 4. Named entities: &copy; for ©, &reg; for ®, &trade; for ™
  • 5. Numeric: &#9829; decimal, &#x2665; hex — any Unicode character
  • 6. In attribute values: use &amp; for & in URLs
🌍

Real-World Examples

  • Code tutorial sites use &lt; and &gt; to show HTML tags as visible text
  • Footer copyright: &copy; 2024 Applaa Ltd
  • Prices: &pound;9.99 → £9.99, &euro;9.99 → €9.99
  • Non-breaking space: 20&nbsp;mph keeps number and unit together on one line
💡

Key Facts

  • There are over 2,000 named HTML entities, but you only need ~10 in practice
  • Modern HTML5 with UTF-8 encoding means you can type most symbols directly — entities are mainly for reserved chars
  • Failing to escape < and > in user content can cause XSS (cross-site scripting) attacks
  • &nbsp; adds non-collapsing space — useful occasionally, but CSS margin/padding is usually better
⚠️

Watch Out!

Never display raw user input directly in HTML without escaping it. If a user types <script>alert('hacked')</script> and you show it unescaped, it runs in other browsers. Always encode user input (or use a framework that escapes by default, like React).

📌

Remember

Escape reserved chars: < = &lt;, > = &gt;, & = &amp;. Modern UTF-8 means most symbols can be typed directly. Always sanitise user input to prevent XSS.

What You Learned

  • HTML entities escape reserved chars and add special symbols — format: &name; or &#number;
  • Must escape < > & from user input; framework templates like React do this automatically
  • Unlocks: displaying code in docs, safe user content, special characters in any language or currency

Key Facts

  • There are over 2,000 named HTML entities, but you only need ~10 in practice
  • Modern HTML5 with UTF-8 encoding means you can type most symbols directly — entities are mainly for reserved chars
  • Failing to escape < and > in user content can cause XSS (cross-site scripting) attacks
  • &nbsp; adds non-collapsing space — useful occasionally, but CSS margin/padding is usually better

Real-World Examples

• Code tutorial sites use <code>&amp;lt;</code> and <code>&amp;gt;</code> to show HTML tags as visible text • Footer copyright: <code>&amp;copy; 2024 Applaa Ltd</code> • Prices: <code>&amp;pound;9.99</code> → £9.99, <code>&amp;euro;9.99</code> → €9.99 • Non-breaking space: <code>20&amp;nbsp;mph</code> keeps number and unit together on one line

Remember

Escape reserved chars: < = &lt;, > = &gt;, & = &amp;. Modern UTF-8 means most symbols can be typed directly. Always sanitise user input to prevent XSS.

Quick Quiz

1 / 2

&amp; shows?