JavaScript Unicode escaper — \uXXXX encode and decode

Type text with accents, symbols or emoji and get it back with every non-ASCII character written as a JavaScript \uXXXX escape, or paste escaped text and read it as normal characters.

Live demo · real result from this tool
Mode

Escaped text

Cr\u00e8me br\u00fbl\u00e9e \u2014 \u6771\u4eac \ud83d\ude00
Characters escaped7

Processed on your device — nothing is uploaded.

How to use the JS Unicode escaper

  1. Type or paste into Text.
  2. Choose the Mode: Escape to write characters as escapes, or Unescape to turn escapes back into characters.
  3. When escaping, pick an Escape style: \uXXXX (surrogate pairs for emoji, works everywhere) or \u{…} (ES2015+).
  4. Tick Escape every character, not just non-ASCII if you need every letter escaped.
  5. 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:

  • \uXXXX style. 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 \e9 instead.
  • 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?
When a file must stay pure ASCII. Examples are code served without a charset header, build tools or old editors that mangle UTF-8, minified bundles you want to diff byte by byte, and string tables inside source for several languages.
Which escape style should I pick?
The \uXXXX style works in every JavaScript engine and in JSON. The \u{…} style is shorter for emoji and other characters above U+FFFF, but needs ES2015 or later and is not valid in JSON.
Why does one emoji become two escapes?
JavaScript strings are made of 16-bit units. Characters above U+FFFF, such as 😀 (U+1F600), are stored as a surrogate pair, so in \uXXXX style they need two escapes, 😀.
Why is \n not decoded?
The decoder only handles Unicode and hex escapes. Escapes such as \n, \t and \" are left as written. For a full string unescape, use the string escaper.
Are spaces and line breaks escaped?
Not by default. Only characters above the printable ASCII range are escaped, so spaces, tabs and line breaks pass through. Tick "Escape every character, not just non-ASCII" to escape everything.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close