How to use the HTML entity encoder
- Choose Mode: Encode escapes text for HTML, Decode turns entities back into characters.
- Paste text or HTML into the left pane. The result updates as you type.
- Keep Escape quotes on (the default) when the output may go inside attribute values.
- Turn on Escape non-ASCII to write every non-ASCII character as a numeric entity.
Example
The sample input:
<a href="/search?q=a&b">Tom & Jerry's "Café" — 5 < 7</a>
encodes to:
<a href="/search?q=a&b">Tom & Jerry's "Café" — 5 < 7</a>
Decoding that output gives back the original text exactly. With Escape non-ASCII, Café 😀 becomes Café 😀.
What gets encoded and decoded
| Character | Encoded as | Notes |
|---|---|---|
& |
& |
Always escaped |
< and > |
< and > |
Always escaped |
" |
" |
With Escape quotes |
' |
' |
With Escape quotes; ' is not recognized by old HTML 4 parsers |
| non-ASCII | é |
With Escape non-ASCII |
When decoding, numeric entities are converted for every valid code point, while invalid ones such as surrogates become the replacement character �. Named entities come from a curated list of about 170 common names. The full HTML5 list has 2,231, so anything outside the curated list is left as-is, for example &bogus;, and the warning shows which names were skipped.
Where escaping is and isn’t enough
Entity escaping is the correct defense for text placed inside HTML elements and quoted attributes. It is not enough for:
- values inside
<script>blocks or inline event handlers (onclick), - CSS in
<style>orstyle="", hrefandsrcvalues, which also need URL validation to blockjavascript:links,- unquoted attribute values.
Template engines apply the right escaping automatically. If you see text like &amp; or &lt; on a page, the content was escaped twice. Decode it once here to find the original, then remove the extra escaping step from your pipeline. Each decode removes one layer, so &amp;lt;b&amp;gt; becomes &lt;b&gt; after the first pass. Once you have plain markup back, run it through the HTML Formatter to read it comfortably. Use this tool for one-off content, documentation, email templates and debugging double-escaped output such as &amp;.
Escaping in code
const escapeHtml = (s) =>
s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
import html
html.escape('Tom & "Jerry"') # 'Tom & "Jerry"'
html.unescape('© © …') # '© © …'
For URLs, use URL Encode / Decode. For strings inside JSON, use JSON Escape / Unescape.
Frequently asked questions
Which characters are escaped when encoding?
Ampersand, less-than and greater-than are always escaped as &, < and >. With Escape quotes on, double quotes become " and single quotes become ', which makes the output safe inside quoted HTML attributes as well as element text.
Does escaping HTML protect my site from XSS?
Only in the right context. Entity escaping makes text safe inside HTML element content and quoted attributes. It does not make data safe inside JavaScript, CSS, URLs or unquoted attributes. In an application, rely on your framework's automatic escaping (React, Vue, Svelte, Django, Jinja and others) instead of escaping by hand.
Which named entities can it decode?
All numeric entities (decimal like © and hex like ©) and a curated set of about 170 common named entities, including &, , ©, …, typographic quotes and dashes, arrows, math symbols, Greek letters and accented Latin letters. Unknown names are left unchanged and listed in a warning.
When should I use Escape non-ASCII?
Turn it on when the HTML has to survive a channel that is not UTF-8 safe, such as some legacy email systems or templates with the wrong charset. Every character outside ASCII, including emoji, is written as a hex entity like é. For normal UTF-8 pages, leave it off.
Is my HTML uploaded?
No. Encoding and decoding run in your browser tab, and nothing is uploaded.
Last updated