๐Ÿท๏ธ HTML Entities Reference: Complete Character Encoding Guide

๐Ÿ“… August 26, 2026 ๐Ÿ“– 7 min read ๐Ÿท๏ธ Reference

HTML entities are essential for web developers. Whether you're displaying special characters, preventing XSS attacks, or working with multilingual content, understanding HTML entities is crucial.

This guide covers everything you need to know about HTML entities โ€” what they are, when to use them, and a complete reference of common entities.

โšก Encode HTML Entities Instantly

Convert special characters to HTML entities and vice versa.

Open HTML Encoder โ†’

๐Ÿค” What Are HTML Entities?

HTML entities are character sequences that represent special characters in HTML. They start with & and end with ;.

Why Do We Need Them?

๐Ÿ“ Types of HTML Entities

1. Named Entities

&lt;     โ†’ <     (less than)
&gt;     โ†’ >     (greater than)
&amp;    โ†’ &     (ampersand)
&quot;   โ†’ "       (double quote)
&apos;   โ†’ '       (apostrophe)
&nbsp;   โ†’ (non-breaking space)
&copy;   โ†’ ยฉ       (copyright)
&reg;    โ†’ ยฎ       (registered trademark)
&trade;  โ†’ โ„ข       (trademark)

2. Numeric Entities (Decimal)

&#60;    โ†’ <     (less than)
&#62;    โ†’ >     (greater than)
&#38;    โ†’ &     (ampersand)
&#34;    โ†’ "       (double quote)
&#169;   โ†’ ยฉ       (copyright)
&#8364;  โ†’ โ‚ฌ       (euro sign)

3. Numeric Entities (Hexadecimal)

&#x3C;   โ†’ <     (less than)
&#x3E;   โ†’ >     (greater than)
&#xA9;   โ†’ ยฉ       (copyright)
&#x20AC;  โ†’ โ‚ฌ       (euro sign)

๐Ÿ“‹ Essential HTML Entities Reference

Must-Escape Characters (Security)

CharacterEntityCodePurpose
<&lt;&#60;Less than (tag start)
>&gt;&#62;Greater than (tag end)
&&amp;&#38;Ampersand
"&quot;&#34;Double quote
'&apos;&#39;Apostrophe
Security Tip: Always escape these 5 characters when displaying user-generated content to prevent XSS attacks!

Common Symbols

CharacterNamedNumeric
ยฉ&copy;&#169;
ยฎ&reg;&#174;
โ„ข&trade;&#8482;
โ‚ฌ&euro;&#8364;
ยฃ&pound;&#163;
ยฅ&yen;&#165;
ยฐ&deg;&#176;
ยฑ&plusmn;&#177;
ร—&times;&#215;
รท&divide;&#247;

Whitespace & Special

DescriptionEntityResult
Non-breaking space&nbsp;Space that won't break
En space&ensp;Width of 'n'
Em space&emsp;Width of 'm'
Thin space&thinsp;Narrow space
Soft hyphen&shy;Optional hyphen

Arrows

CharacterEntityCharacterEntity
โ†&larr;โ†’&rarr;
โ†‘&uarr;โ†“&darr;
โ†”&harr;โ†ต&crarr;

๐Ÿ’ป Encoding in Code

JavaScript

// Encode HTML entities
function encodeHTML(str) {
  return str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}

// Decode HTML entities
function decodeHTML(str) {
  const textarea = document.createElement('textarea');
  textarea.innerHTML = str;
  return textarea.value;
}

PHP

// Encode
$encoded = htmlspecialchars($string, ENT_QUOTES, 'UTF-8');

// Decode
$decoded = html_entity_decode($string, ENT_QUOTES, 'UTF-8');

Python

import html

# Encode
encoded = html.escape('<script>alert("XSS")</script>')

# Decode
decoded = html.unescape('&lt;script&gt;')

โš ๏ธ Common Mistakes

  1. Forgetting to escape in attributes: <img alt="&quot;test&quot;">
  2. Double encoding: &amp;lt; instead of &lt;
  3. Missing semicolon: &lt (invalid)
  4. Encoding in URLs: Use URL encoding, not HTML entities

โœ… Best Practices

๐Ÿ”— Conclusion

HTML entities are a fundamental part of web development. They ensure your content displays correctly, prevents security vulnerabilities, and allows you to use any character in your HTML documents.

Bookmark this reference for quick lookup, and remember: when in doubt, encode it!