Escape & Unescape
Escape or unescape strings for HTML, XML, JSON and JS.
What is Escape & Unescape
This tool escapes and unescapes strings for four formats: HTML, XML, JSON and JavaScript. Special characters (< > & " ' and line breaks) become safe escape sequences, and escaped text can be restored to the original. Commonly used before embedding strings in code or when reading logs.
🔒 Everything runs in your browser. Nothing is uploaded.
What this tool actually does with your file
- Where it runs
- In your browser, on this page
- Upload
- None — the file never leaves your device
- Offline
- Works with the network disconnected
A dead Netscape function, kept alive by legacy data
escape() produces %uXXXX for characters above U+00FF and %XX for those below. That is a different scheme from encodeURIComponent, which always emits the UTF-8 bytes as %XX. One Chinese character becomes one %uXXXX under escape and three %XX sequences under percent-encoding.
The function was deprecated because it cannot represent non-BMP characters properly and because %uXXXX is not a valid URI escape — no standard parser outside JavaScript understands it. unescape() is its inverse and equally deprecated. Both still exist because decades of bookmarks, cookies and log lines contain their output.
Why the mismatch bites
Bookmarks and cookies written by old browsers contain %u escapes; modern URL parsers pass them through untouched, so the value arrives at the server still encoded. Servers that decode only standard percent-encoding then store the literal string %u4e2d, and a later round trip double-encodes it. That is the origin of the mojibake chains people describe as 'broken Chinese in old links'.
The reverse mistake is applying unescape() to standard percent-encoding. It handles %XX, but it decodes each byte as a Latin-1 character rather than assembling UTF-8, so a three-byte CJK character becomes three mojibake characters instead of one correct one.
The replacement that does the same job
For anything new, use encodeURIComponent / decodeURIComponent and keep the payload in UTF-8. It is standard, it round-trips through every language, and it matches what browsers put on the wire.
Only reach for %u handling when the data already contains it. In that case treat the conversion as a migration step — convert once, store the result, and stop generating new %u escapes, because every legacy escape left in a system has to be explained to the next person who touches it.
How to use it
- 1.Pick the format (HTML/XML/JSON/JS)
- 2.Pick direction (escape/unescape)
- 3.Enter text and run
How Escape & Unescape works under the hood
Encoding tools convert between representations of the same bytes: Base64, percent-encoding, hex, HTML entities, Unicode escapes. A correct encoder is reversible; a lossy one silently changes the data.
- 1
Get the exact bytes
Text is encoded to UTF-8 bytes with TextEncoder first; binary input is read as an ArrayBuffer. Encoding the wrong byte sequence is the most common cause of a wrong result.
- 2
Apply the encoding rule
Each format has an exact specification: Base64 uses a 64-symbol alphabet with padding, percent-encoding escapes reserved characters as UTF-8 bytes.
- 3
Decode back to verify
Round-tripping the output back to the input is the only honest proof that an encoder is correct. The tool keeps the reverse path available on the same page.
Processing pipeline
Base64 is not encryption
Base64 increases size by about a third and hides nothing: anyone can decode it. It exists to carry binary data through text-only channels such as JSON, email headers and data URLs. If you need confidentiality, use encryption with a key, not an encoding.
Where encoders break
Percent-encoding applied twice turns %20 into %2520; Base64 without padding fails strict decoders; UTF-16 input decoded as UTF-8 produces replacement characters that cannot be recovered. When output looks wrong, check the byte sequence before checking the tool.
Verify it yourself
Encoders are pure functions over bytes. Decode the output again and you should get the input back exactly.
- 1.Open DevTools on this page and switch to the Network tab
- 2.Keep the filter on Fetch/XHR and run the tool
- 3.Confirm no request carries your file — you should see only page assets and fonts
Frequently asked questions
HTML vs XML escaping?
Both convert < > & ", but XML turns single quotes into ' while HTML uses '.
What does JSON escaping cover?
Backslashes, double quotes and control characters like newline and tab become \", \n and \t sequences.
What this kind of conversion cannot keep
Encoding and hashing run through the browser's Web Crypto API or a pure-JavaScript implementation. The output is deterministic: the same input always produces the same digest, so you can verify a result against any other tool.
More in Encoding
On this page
- What is Escape & Unescape
- What this tool actually does with your file
- How it actually behaves
- How to use it
- How it works inside
- Frequently asked questions
Excel formula reference
29 functions with syntax, arguments and a table you can retype.
Browse the list →