HTML Encoder/Decoder
Escape and unescape HTML entities
How to Use HTML Encoder/Decoder
- 1Paste your text or HTML
- 2Click Escape to encode HTML entities, or Unescape to decode them
- 3Copy or download the result
About HTML Encoder/Decoder
HTML Escape & Unescape converts characters that have special meaning in HTML (&, <, >, ", ') to their HTML entity equivalents (&, <, >, ", '), and vice versa. Proper escaping prevents cross-site scripting (XSS) attacks and display bugs when rendering user content in web pages.
Use this tool when building HTML templates, generating email HTML, displaying code snippets in a browser, or preparing any text content for safe insertion into HTML documents. Failing to escape user-generated content is one of the most common web security vulnerabilities.
All escaping and unescaping runs entirely in your browser with no server involved.
Key Features of HTML Encoder/Decoder
- Escape the five core HTML special characters: &, <, >, ", '
- Unescape HTML entities back to their original characters
- Prevents XSS vulnerabilities when inserting text into HTML
- Handles named entities (&, <, >, ", ')
- One-click copy for escaped and unescaped output
- Works entirely in-browser — no data is sent to any server
- Instant conversion with real-time output
- Useful for rendering code examples and user-generated content safely
Supported Formats
Input Formats
Output Formats
Escapes the five core HTML special characters per HTML5 specification. Does not encode extended Unicode characters as named entities.
Examples
Escape a code snippet for display in HTML
Make source code render as text rather than being parsed as HTML tags.
Input
<div class="box">Hello & World</div>
Output
<div class="box">Hello & World</div>
Unescape HTML entities from a database record
Convert stored HTML entities back to readable characters for editing.
Input
It's a "great" day & we're happy
Output
It's a "great" day & we're happy
Common Use Cases
- Safely inserting user-generated content into HTML templates to prevent XSS
- Displaying code examples in blog posts without them being parsed as HTML
- Preparing text for insertion into HTML email templates
- Decoding HTML entities stored in databases for editing
- Converting API response text containing entities to readable strings
- Escaping strings before inserting them into innerHTML calls
Troubleshooting
Entities appear double-encoded like &amp;
Solution
The text was already escaped before you escaped it again. Unescape first to get the original characters.
Not all special characters are being escaped
Solution
This tool escapes the five core HTML characters. Extended entities like © or are not in scope.
Unescaping does not convert all entities
Solution
This tool handles the five core entities. Rare named entities like → may not be decoded — use a full HTML parser for comprehensive decoding.
Frequently Asked Questions
Why escape HTML?
Unescaped characters like < and > are interpreted as HTML tags. Without escaping, user-submitted text containing <script> tags can execute arbitrary JavaScript — a cross-site scripting (XSS) attack.
Which characters are escaped?
The five core HTML special characters: & → &, < → <, > → >, " → ", ' → '.
What is the difference between HTML escaping and URL encoding?
HTML escaping converts characters to HTML entities for safe rendering inside HTML. URL encoding converts characters to %XX hex format for safe use in URLs.
Should I escape or sanitize user content?
For displaying user content as plain text in HTML, escaping is sufficient. If you need to allow some HTML tags, use a trusted HTML sanitizer library.
Is HTML escaping enough to prevent XSS?
Escaping is the primary defense when inserting text into HTML content. However, the correct escaping strategy depends on context — JS strings, HTML attributes, and URLs each require different rules.
What does &amp; mean?
&amp; is a double-encoded ampersand — it renders as & in the browser. This usually occurs when content is escaped twice.
Is my data sent to a server?
No. All escaping and unescaping is performed in your browser using JavaScript string replacement.
Can I use this to prepare content for JSON inside HTML?
For JSON in HTML (e.g., inside a <script> tag), use JSON.stringify and ensure the string is placed correctly. HTML entity escaping alone is not sufficient.