HTML entities are coded character strings starting with an ampersand and ending with a semicolon used to render reserved and special characters in HTML.
An HTML Entity is a character sequence that begins with an ampersand (&) and concludes with a semicolon (;). It is used in web development to display reserved syntax characters (such as < and >), invisible characters (like non-breaking spaces), and symbols outside the standard ASCII character set without conflicting with HTML parser tag tokens.
You can encode raw text to HTML entities or decode entities back to readable text using our free browser-based HTML Entities Encoder & Decoder tool.
In HTML and XML syntax, five characters are strictly reserved because they define tag boundaries, attributes, and entity declarations. If used raw within text nodes, the browser parser interprets them as structural markup:
| Character | Meaning | Named Entity | Decimal Entity | Hexadecimal Entity |
|---|---|---|---|---|
< |
Less than (Tag start) | < |
< |
< |
> |
Greater than (Tag end) | > |
> |
> |
& |
Ampersand (Entity start) | & |
& |
& |
" |
Double quotation mark | " |
" |
" |
' |
Single quote (Apostrophe) | ' |
' |
' |
| Symbol | Description | Named Entity | Decimal Entity | Hex Entity |
|---|---|---|---|---|
|
Non-breaking space | |
  |
  |
© |
Copyright | © |
© |
© |
® |
Registered trademark | ® |
® |
® |
™ |
Trademark symbol | ™ |
™ |
™ |
— |
Em dash | — |
— |
— |
– |
En dash | – |
– |
– |
« |
Left-pointing double angle | « |
« |
« |
» |
Right-pointing double angle | » |
» |
» |
• |
Bullet point | • |
• |
• |
€ |
Euro currency | € |
€ |
€ |
£ |
British Pound | £ |
£ |
£ |
¥ |
Japanese Yen | ¥ |
¥ |
¥ |
← |
Left arrow | ← |
← |
← |
→ |
Right arrow | → |
→ |
→ |
HTML entities can be authored in three interchangeable formats:
&name;): Human-readable and intuitive (e.g., © for ©). However, HTML5 supports over 2,200 named entities, and older XML parsers or strict XML contexts may only recognize the 5 predefined entities (<, >, &, ", ').&#[0-9]+;): References the Unicode code point in base-10 (e.g., © for ©). Universally supported by all browser engines, email clients, and XML/RSS parsers.&#x[0-9A-Fa-f]+;): References the Unicode code point in base-16 hexadecimal (e.g., © for ©). Preferred when cross-referencing Unicode charts (such as U+00A9).Failing to properly encode user-supplied text before rendering it into an HTML document is the primary catalyst for Cross-Site Scripting (XSS) attacks. If an attacker submits <script>alert(document.cookie)</script> and the server renders it unescaped, the browser will execute arbitrary JavaScript within the victim's session.
&, <, and > to convert malicious tags into harmless text.<input value="..."> or <a title="...">, attributes delimited by quotes must escape " and ' to prevent attribute breakout attacks (" onfocus="evilCode()").<script> tags. Variables injected into JavaScript must be serialized using strict JSON escaping (JSON.stringify()) rather than HTML entity replacement.// High-performance HTML escaping without DOM overhead
const HTML_ESCAPE_MAP = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
};
export function escapeHtml(str) {
return str.replace(/[&<>"']/g, (char) => HTML_ESCAPE_MAP[char]);
}
export function unescapeHtml(htmlStr) {
const doc = new DOMParser().parseFromString(htmlStr, 'text/html');
return doc.documentElement.textContent || '';
}
// Example usage:
console.log(escapeHtml('<script>alert("XSS")</script>'));
// Output: <script>alert("XSS")</script>
import html
# Escape unsafe HTML characters
raw_input = '<div class="profile">Tom & Jerry</div>'
safe_html = html.escape(raw_input, quote=True)
# Result: '<div class="profile">Tom & Jerry</div>'
# Unescape entities back to standard Unicode characters
original_text = html.unescape('© 2026 DevFlow — All Rights Reserved')
# Result: '© 2026 DevFlow — All Rights Reserved'
HTML Entity encoding converts characters that break HTML DOM parsing (like < to <), whereas URL Encoding converts characters that break URI query strings and path routing (like spaces to %20 or / to %2F). They operate on different protocols and should not be used interchangeably.
and why is it used? stands for Non-Breaking Space. In standard HTML, web browsers collapse multiple sequential whitespace characters into a single space. Using forces the browser to display multiple contiguous spaces and prevents an automatic line break between two words (such as between numbers and units: 100 km/h).
No. HTML escaping only neutralizes markup injection within standard HTML body text and attribute values. It does not protect against DOM-based XSS when passing values to eval(), innerHTML, setTimeout(), or javascript: URI schemes. Defense-in-depth requires a strict Content Security Policy (CSP) and modern frameworks (such as React or Next.js) that automatically escape rendered JSX variables.
Yes, for most foreign characters. Because modern web pages use <meta charset="utf-8">, you can directly type characters like ©, €, é, or emojis directly into source files without numeric entities. However, the five reserved syntax characters (<, >, &, ", ') must always be escaped whenever they represent raw content rather than HTML markup. Use our HTML Entities tool to convert files reliably.
Free, browser-based utilities to test, generate, and inspect HTML Entities & Character Encoding payloads directly.