HTML Escape & Unescape: Entity Encoder
Escape raw HTML for safe display and decode entities back to text, bidirectionally and in real time, entirely in your browser.
How the two directions are implemented
Some online tools decode entities by assigning your text to a live element's innerHTML, which parses it as markup: a pasted <img onerror=…> executes on the spot. This tool never does that.
- Escaping is pure string replacement: a character-to-entity table applied with a regular expression. No parser is involved, so nothing can be interpreted.
- Unescaping uses a detached
<textarea>: a textarea's content is RCDATA in the HTML specification, meaning the parser decodes character references but never creates elements from it. That gives full coverage of every named and numeric entity with no execution path, and the element is never attached to the page. - Bidirectional Sync: Paste raw code on the left to secure it for transport, or paste an escaped payload on the right to revert it to readable HTML instantly.
- Air-Gapped Operation: No payload data is ever transmitted to external servers. All cryptographic string manipulation occurs locally.
XSS Vulnerability Prevention
Sanitize raw user input from forms, comments, and text areas before storing it in your database to prevent Cross-Site Scripting (XSS) injection attacks across your application.
JSON Payload Escaping
Safely encode complex HTML strings so they can be embedded directly within JSON API payloads without breaking string boundaries or disrupting downstream parsers.
Frontend Code Display
Convert raw HTML elements into secure, escaped entities so they render visibly as code blocks in the DOM rather than being interpreted and executed by the browser engine.
Quick Testing Templates
Load an example to see what escaping changes. The second one is the kind of untrusted input a comment box or form field might receive, and shows why it must be escaped before it is put into a page.
HTML entities list: the characters you will actually need
Each character with its named entity and its decimal and hex numeric references. Any of the three forms works in HTML; numeric references work for every Unicode character, named ones only for the characters HTML defines a name for. Paste any of them into the right pane above to decode it.
| Character | Named | Decimal | Hex | Notes |
|---|---|---|---|---|
| & | & | & | & | Ampersand: always escape it first |
| < | < | < | < | Less-than: starts a tag |
| > | > | > | > | Greater-than |
| " | " | " | " | Double quote: escape inside attribute values |
| ' | ' | ' | ' | Apostrophe (' is valid in HTML5 but not in old HTML 4) |
| (non-breaking space) | |   |   | Non-breaking space |
| © | © | © | © | Copyright |
| ® | ® | ® | ® | Registered trade mark |
| ™ | ™ | ™ | ™ | Trade mark |
| € | € | € | € | Euro |
| £ | £ | £ | £ | Pound sterling |
| ¥ | ¥ | ¥ | ¥ | Yen |
| ₹ | ₹ | ₹ | ₹ | Indian rupee (no named entity) |
| — | — | — | — | Em dash |
| – | – | – | – | En dash |
| … | … | … | … | Ellipsis |
| • | • | • | • | Bullet |
| × | × | × | × | Multiplication sign |
| ÷ | ÷ | ÷ | ÷ | Division sign |
| ° | ° | ° | ° | Degree |
| « | « | « | « | Left angle quote |
| » | » | » | » | Right angle quote |
| → | → | → | → | Right arrow |
| ✓ | ✓ | ✓ | ✓ | Check mark (the name is HTML5 only) |
Only the first five must be escaped to put text safely into HTML. The rest are optional in a UTF-8 page, where you can type the character itself; entities are useful when an editor, an email system or a template engine might mangle it.
Frequently Asked Questions
If an online tool sets your pasted text to a live element's innerHTML in order to read the browser's parsed entities, inline event handlers (like onerror) within your text can immediately execute. Layerbit escapes with pure string replacement and unescapes through a detached textarea, whose content is RCDATA: the parser decodes character references but never creates elements from it, so nothing can run.
The extended profile (default) escapes ampersands (&), less than/greater than symbols (< >), double/single quotes (" '), forward slashes (/), backticks (`), and equals signs (=). The essential profile escapes only the first five, and a third profile additionally turns every non-ASCII character into a hex reference.
No. While this tool is perfect for ad-hoc preparation and debugging, enterprise applications should never trust client-side input exclusively. You must always sanitize strings on your backend server before executing SQL inserts or NoSQL document updates.
The five characters, and the order they must be replaced in
HTML escaping replaces characters that carry structural meaning with entity references. There are five that matter, and one ordering rule that catches people out:
&→&— must be replaced first, or you re-escape the semicolons of your own entities and produce&lt;, which renders visibly as<.<→<and>→>— otherwise your value starts or ends a tag."→"and'→'— these end a quoted attribute value. Prefer the numeric'over', which was not in HTML 4 and is unrecognised by some legacy parsers.
Get that right and a value is safe in exactly one context: as text between tags. Everywhere else needs different handling, which is the subject of our guide on contextual output escaping.
Unquoted attributes
<input value={{ x }}> is unsafe even when escaped, because an unquoted value ends at the first space. A payload of x onfocus=alert(1) autofocus contains none of the five characters and adds an event handler. Always quote attributes.
Inside <script>
HTML escaping is the wrong tool here and corrupts the data. Worse, the literal text </script> ends the block even inside a JavaScript string, because the HTML tokeniser runs before the JS parser. Serialise as JSON into a data attribute instead.
Inside href
Escaping produces well-formed HTML and does not help: javascript:alert(1) contains no character that escaping touches. The defence is a scheme allowlist — accept http:, https:, mailto: and reject the rest.
Escape on output, never on input
A persistent anti-pattern is escaping values as they arrive and storing the escaped form. It fails for three reasons worth knowing:
- The context is unknown at input time. The same comment might later be rendered as HTML, sent as a plain-text email, returned in a JSON API response and included in a CSV export. Each needs different treatment, and HTML entities in a plain-text email are simply wrong.
- Your data is corrupted. The stored value is no longer what the user typed, so search, sorting, length checks and comparisons all operate on
&instead of&. - Double escaping. When a correctly written template escapes the already-escaped value, users see
&lt;on the page — and the usual "fix" is to disable escaping in that template, which removes the real protection.
Store exactly what the user typed; escape at the moment of rendering, for the destination it is rendering into. This tool's unescape direction is genuinely useful for diagnosing the double-escaping case: paste the mangled output and you can see how many rounds of escaping it went through.
Escaping is not sanitising
These solve different problems. Escaping renders a value as inert text, so <b>hi</b> displays as those literal characters — correct for usernames, titles and comments. Sanitising parses the value as HTML and strips everything not on an allowlist while keeping the rest live — correct only when users are meant to submit formatting. If you need sanitising, use a maintained library such as DOMPurify and never a regular expression: HTML is far too irregular for pattern matching, and every hand-rolled tag stripper has been bypassed via malformed markup that browsers helpfully "correct" into something executable.
Changelog
- v1.5.0 Added an escape profile: the essential five for HTML text and attributes, the extended set that also covers unquoted-attribute breakouts, or everything non-ASCII as hex references for charset-less destinations.
- v1.4.0 Unescaping now decodes every HTML5 named entity (all 2,231 of them), plus decimal and hex numeric references, rather than the eight the tool itself produces.
©, and😀all round-trip. - v1.3.0 Added file upload and drag-and-drop to both panes.
- v1.2.0 Upgraded the rendering engine to provide bidirectional synchronization without infinite loop conflicts.
- v1.1.0 Expanded the regex dictionary matrix to capture backticks and equals signs to mitigate advanced injection variants.
- v1.0.0 Initial deployment of the zero-trust string replacement matrix.