About this tool
HTML Entities are standardized codes defined by the W3C to represent reserved syntax characters and invisible symbols safely inside web pages. Because delimiters like `<`, `>`, `&`, and quotes indicate markup structure, outputting raw user input directly triggers DOM corruption and dangerous Cross-Site Scripting (XSS) vulnerabilities. This tool provides bidirectional conversion between raw text and HTML entities (Named and Numeric decimal/hex), safeguarding web application security.
How to Use This Tool (Step-by-Step)
Enter Raw Text or Entity String
Paste unescaped text containing markup symbols, user comment strings, or existing HTML entities into the input box.
Select Encode or Decode Mode
Click 'HTML Encode' to convert dangerous symbols into safe entities (e.g., `<` becomes `<`), or click 'HTML Decode' to restore plain characters.
Copy Sanitized Entity String
The sanitized result displays immediately. Copy with one click to embed safely inside backend templates or documentation.
Comprehensive XSS Delimiter Escaping
Strictly sanitizes the five core XSS attack vectors (`&`, `<`, `>`, `"`, `'`), completely blocking client-side script injection attempts.
Named & Numeric Entity Support
Supports both human-readable named entities (`©` for ©) and robust numeric decimal (`©`) / hex (`©`) entities.
100% Client-Side Air-Gapped
Text transformation runs exclusively inside your browser's local sandbox memory. Internal API payloads remain completely secure.
Web Security Principles & Escaping Gotchas
- •Escape on output, not on database insert: Storing raw entities in databases corrupts text search and mobile API payloads. Store plain text; escape upon HTML rendering.
- •Avoid double escaping: Escaping an already encoded string turns `&` into `&amp;`, exposing ugly raw entity codes on the frontend.
- •HTML escaping does not secure href attributes: Sanitizing HTML entities cannot prevent `javascript:alert(1)` pseudo-protocol links. Always validate URL protocols.
Code & Transformation Examples
Malicious XSS Injection Sanitization Benchmark
<script>alert("XSS 漏洞攻击 & 盗取 Cookie!")</script><script>alert("XSS 漏洞攻击 & 盗取 Cookie!")</script>* Once escaped, the browser renders the code as safe visible text rather than executing it as active JavaScript.
JavaScript Native HTML Escaping Implementation
function escapeHtml(str) {
return str.replace(/[&<>"']/g, (m) => ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
})[m]);
}function unescapeHtml(html) {
const el = document.createElement('textarea');
el.innerHTML = html;
return el.value;
}* Leveraging `textarea.innerHTML` is the most lightweight browser-native trick for entity decoding.
Frequently Asked Questions
Q: Should single quotes be escaped as ' or '?
A: Always use numeric `'`. While XML supports `'`, legacy versions of Internet Explorer failed to decode it. Numeric entities are 100% universally compatible.
Q: What are common symbol entities like Copyright and Trademark?
A: Copyright © is `©` (`©`); Registered ® is `®` (`®`); Trademark ™ is `™` (`™`); Non-breaking space is ` `.
Q: Do Chinese characters still need numeric entity encoding under UTF-8?
A: No. In the modern UTF-8 era, CJK characters are natively supported without conversion to numeric unicode entities like `中`. Only reserved markup symbols require escaping.