How to use the JS Unicode escaper
- Type or paste into Text.
- Choose the Mode: Escape to write characters as escapes, or Unescape to turn escapes back into characters.
- When escaping, pick an Escape style:
\uXXXX(surrogate pairs for emoji, works everywhere) or\u{…}(ES2015+). - Tick Escape every character, not just non-ASCII if you need every letter escaped.
- Copy the Escaped text or Decoded text. When escaping, Characters escaped shows how many were changed.
What it does and when to use it
A string such as "Crème brûlée" in a source file only works if every tool along the way reads the file as UTF-8. Writing the special characters as escapes removes that risk: the file contains only ASCII, and the JavaScript engine turns the escapes back into the same characters when it runs. The reverse direction helps when you find é-style text in a minified bundle, a log or an API response and want to read it.
For other encodings there are related tools. The JS regex escaper escapes characters that have a meaning in patterns, the string escaper handles quotes and line breaks for JSON, JavaScript, SQL and more, and text to Unicode shows code points such as U+00E9.
How it works
The tool walks through the text one code point at a time. Any code point above ~ (U+007E), or every one if you ticked the option, is replaced:
\uXXXXstyle. Four lowercase hex digits. Code points above U+FFFF are split into a high and low surrogate, each written as its own escape.\u{…}style. Characters up to U+FFFF still use four digits; anything above is written once, such as\u{1f600}.
Unescape finds \u with four hex digits, \u{…} with one to six digits, and \x with two digits, and replaces each with its character. Pairs of surrogate escapes join into the original emoji. These are the escape forms defined for string literals in the ECMAScript specification.
Worked examples
Escape with \uXXXX. Crème brûlée — 東京 😀 gives:
Crème brûlée — 東京 😀
Characters escaped: 7. The emoji counts as one character but needs two escapes.
Escape with \u{…}. The same text ends in 東京 \u{1f600} instead; everything else is unchanged.
Unescape. café \u{1F600} \x41 \n 😀 decodes to café 😀 A \n 😀. The \n stays as two characters because it is not a Unicode escape.
Limits and tips
- Escapes beyond U+10FFFF cause an error, for example
\u{110000} is beyond the Unicode range. - Not for HTML or CSS. Those use
éand\e9instead. - Decoding works anywhere in the text, including inside words, so escaped text in a log line is fine.
Frequently asked questions
When do I need Unicode escapes in JavaScript?
Which escape style should I pick?
Why does one emoji become two escapes?
Why is \n not decoded?
Are spaces and line breaks escaped?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.