Language: English

tools / escape

escape/

Escape and unescape HTML entities, Unicode \uXXXX and JS strings.

Plain text

Escaped

What is character escaping

Character escaping replaces characters that have a special meaning with an equivalent notation; HTML escaping, for example, turns the 5 characters & < > " ' into entities. This page escapes and unescapes HTML entities, Unicode \uXXXX and JavaScript strings without using the DOM or eval.

How it works: each notation fits one place

Example

HTML entities: the angle brackets of the tag, the double quotes of the attribute and the & become entities; everything else stays:

Input
<a href="x">Tom & Jerry</a>
Output
&lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry&lt;/a&gt;

Unicode: each of the two Chinese characters becomes one \u group, ASCII characters stay, and the emoji, being outside the Basic Multilingual Plane, takes two groups:

Input
中文 ok 😀
Output
\u4e2d\u6587 ok \ud83d\ude00

Sources

FAQ

My text has both HTML entities and \u escapes. Can I restore both at once?

Not in one pass: each unescape follows only the type you selected. "HTML entities" recognises only forms like &…;, while "Unicode" and "JS string" recognise only escapes that start with a backslash. Unescape with one type, click "⇄ Use result as input" to put the result back into the input box (the direction switches to "Escape"), then pick the other type and click "Unescape".

Which characters does HTML escaping change, and does Chinese text change?

Only five characters: & becomes &amp;, < becomes &lt;, > becomes &gt;, a double quote becomes &quot; and a single quote becomes &#39;. Chinese text, spaces, line breaks and everything else stay as they are, and nothing is turned into forms like &#x4E2D;. For HTML body text or a quoted attribute value, these five are the ones that need escaping.

Why are some &xxx; entities left unchanged after HTML unescaping?

Named entities the tool does not recognize are kept as they are, without an error. It has a built-in set of common ones (Latin and Greek letters, punctuation, currency, arrows, math symbols and so on); names are case-sensitive and the closing semicolon is required. For a name that is not built in, write it as a numeric entity such as &#20013; or &#x4E2D; and it will decode. A numeric entity whose code point is 0, above 10FFFF or in the surrogate range becomes the replacement character �.

How does Unicode escaping work, and why does an emoji become two \u parts?

Unicode escaping only handles non-ASCII characters; English letters, digits and symbols stay as they are, so "你好 abc" becomes \u4f60\u597d abc, with lowercase hex digits. Characters outside the BMP, such as emoji, are split into a surrogate pair the way JavaScript does it, giving two parts like \ud83d\ude00. When unescaping, both \uXXXX and \u{…} are accepted, adjacent surrogate pairs are merged back into one character, and a malformed \u is left as it is without an error.

Can I paste the JS string escape result straight into code?

Yes, just wrap it in quotes; single or double both work because both kinds of quote are escaped. Backslashes, line breaks and tabs become \\ \n \t, other control characters are written as \xHH, and Chinese text is not escaped. Backticks and ${ are not escaped, so if the text goes into a template literal you have to handle those yourself.

What does the "Unescape failed: Character N: ..." message mean?

The backslash at that position is followed by something invalid. In JS string mode, \x must be followed by two hex digits, \u by four hex digits (or 1 to 6 inside \u{…}), octal escapes such as \1 to \7 are not supported, and a single backslash at the very end is an error too. A common cause is a pasted Windows path: in C:\users the \u is not a valid escape. Backslashes in a path never needed unescaping in the first place.

Can the escaped result be used as a JSON string?

Unescaping works, escaping does not. Sequences such as \n, \", \/ and \uXXXX in a JSON string can be turned back into the original text with "JS string" unescape. But the escape direction writes a single quote as \' and control characters as \xHH, and JSON accepts neither; to produce a valid JSON string, use JSON.stringify.

Is my text uploaded, and is it safe to paste content from an unknown source?

Nothing is uploaded: escaping and unescaping run in your browser, and there is no character limit; with more than a million characters the page waits until you pause for 0.5 seconds before recalculating. HTML and JS unescaping are parsed piece by piece by the tool itself, without the page DOM or eval, so pasting something like <script> just gives you text and never runs it.