Free tool · Developer tools
Unicode escape converter
Paste text into this Unicode escape converter to get its escapes, or paste escapes to get the text back. Café ☕ 😀 becomes Caf\u00E9 \u2615 \uD83D\uDE00 in the JavaScript notation, and the page shows the same text in four more notations with its code points and byte counts.
- Free
- No sign-up
- Runs in your browser
Caf\u00E9 \u2615 \uD83D\uDE00JavaScript, Java and JSON
- \u00E9
- 3 characters escaped
- 8 characters
- Characters (code points)
- 8
- UTF-16 units
- 9
- UTF-8 bytes
- 14
- Escaped characters
- 3
| Character | Code point | JS | ES6 | Python | CSS | UTF-8 bytes |
|---|---|---|---|---|---|---|
| C | U+0043 | \u0043 | \u{43} | \u0043 | \43 | 1 |
| a | U+0061 | \u0061 | \u{61} | \u0061 | \61 | 1 |
| f | U+0066 | \u0066 | \u{66} | \u0066 | \66 | 1 |
| é | U+00E9 | \u00E9 | \u{E9} | \u00E9 | \E9 | 2 |
| (space) | U+0020 | \u0020 | \u{20} | \u0020 | \20 | 1 |
| ☕ | U+2615 | \u2615 | \u{2615} | \u2615 | \2615 | 3 |
| 😀 | U+1F600 | \uD83D\uDE00 | \u{1F600} | \U0001F600 | \1F600 | 4 |
How to use the Unicode Escape Converter
- Paste your text or your escape sequences into the Text box.
- Set the Direction to text to escape sequences, or the other way round.
- Pick the Notation your language uses, and choose whether every character or only non ASCII characters are escaped.
- Press Copy the result, or Use the result as the new text to run the conversion back and check it.
What does a Unicode escape converter do?
Source code, JSON files and style sheets are safest when they hold plain ASCII. A Unicode escape writes any other character as a short code made of its number, so the file survives every editor and encoding. The converter works both ways. Typing Café ☕ 😀 with the default settings gives Caf\u00E9 \u2615 \uD83D\uDE00: the letters of Caf stay as they are, é becomes \u00E9, the coffee cup becomes \u2615, and the emoji becomes the pair \uD83D\uDE00. 3 of the 8 characters were escaped.
The reverse direction reads the same notation and returns the text. Decoding Caf\u00E9 \u2615 \uD83D\uDE00 gives back Café ☕ 😀, with 4 escapes read. Hex digits may be upper or lower case. Text that is not an escape is copied through untouched, so a Windows path such as C:\path passes unchanged.
The table under the result lists each distinct character once, in the order it first appears, with its code point, its escape in four notations and the number of UTF-8 bytes it takes. The sample text is 8 characters, 9 UTF-16 units and 14 UTF-8 bytes, which shows why a character count and a byte count are different numbers.
| Character | Code point | JS | ES6 | Python | CSS | UTF-8 bytes |
|---|---|---|---|---|---|---|
| C | U+0043 | \u0043 | \u{43} | \u0043 | \43 | 1 |
| a | U+0061 | \u0061 | \u{61} | \u0061 | \61 | 1 |
| f | U+0066 | \u0066 | \u{66} | \u0066 | \66 | 1 |
| é | U+00E9 | \u00E9 | \u{E9} | \u00E9 | \E9 | 2 |
| (space) | U+0020 | \u0020 | \u{20} | \u0020 | \20 | 1 |
| ☕ | U+2615 | \u2615 | \u{2615} | \u2615 | \2615 | 3 |
| 😀 | U+1F600 | \uD83D\uDE00 | \u{1F600} | \U0001F600 | \1F600 | 4 |
Why does an emoji need two \u escapes?
A \uXXXX escape holds exactly four hex digits, so it can name only the code points up to U+FFFF. Code points above that, such as U+1F600, are written as a surrogate pair. Subtract 0x10000 to get F600. The top ten bits, 3D, are added to D800 and give the high surrogate D83D. The low ten bits, 200, are added to DC00 and give the low surrogate DE00. Joined, they read \uD83D\uDE00.
Notations that take a longer escape avoid the pair. ES6 writes the same emoji as \u{1F600}, Python writes \U0001F600 and CSS writes \1F600. The decoder joins a pair back into one character, so the count of characters stays at 8 even though the JavaScript text has 9 units.
Which Unicode escape notation should I use?
Use the one the receiving language reads. The JavaScript form works in JavaScript, Java and JSON strings, with one catch in Java: the compiler reads \u escapes before it reads strings, so \u000A or \u0022 inside a literal breaks the code. The ES6 form needs an engine that supports ES2015 or later, and it removes the pairs. Python takes \u with four digits and \U with eight, and each length is fixed. CSS takes one to six hex digits and one optional space after them, so the converter always adds that space. The U+XXXX form is a way to write a code point in documents and is not valid in code, so it always lists every character separated by spaces.
Backslashes need care. In the code notations a backslash in your text is written as two, so a\\b decodes to a backslash again, and in CSS it becomes a\5C b. The Every character choice escapes even plain letters: Hi becomes \u0048\u0069. Line breaks and tabs are escaped as well, since a raw line break would end a string literal. Decoding the JavaScript, ES6 and Python notations also reads \xE9 style escapes, \n, \t and an escaped backslash.
| Notation | Result |
|---|---|
| JavaScript, Java, JSON | Caf\u00E9 \u2615 \uD83D\uDE00 |
| JavaScript ES6 | Caf\u{E9} \u{2615} \u{1F600} |
| Python | Caf\u00E9 \u2615 \U0001F600 |
| CSS | Caf\E9··\2615··\1F600· |
| Code point notation | U+0043 U+0061 U+0066 U+00E9 U+0020 U+2615 U+0020 U+1F600 |
In the CSS row a dot marks the space that follows each escape. For encodings of whole text as bytes rather than code points, the ASCII to hex converter is the better fit, and the JSON escape tool handles quotes and line breaks inside JSON strings.
What does the converter do with bad input?
A broken escape stops the decode and names the problem with its position. For example ab\u12 reports that the escape at position 3 needs four hex digits. A code point above U+10FFFF is refused because Unicode ends there. The page accepts up to 20,000 characters.
A lone surrogate, which is half of a pair with no partner, is kept and flagged in a chip, because many tools cannot store it. Hex and decimal conversions of the same numbers are on the number base converter.
Use it with
- JSON Escape: escape and unescape strings.
- URL Encoder Decoder: percent-encode or decode URLs.
- Number Base Converter: binary, octal, decimal, hex.
Questions
How do I convert text to Unicode escape sequences?
Paste the text, keep the direction on text to escape sequences and pick a notation. Café ☕ 😀 becomes Caf\u00E9 \u2615 \uD83D\uDE00 in the JavaScript notation.
How do I decode \u escape sequences back to text?
Switch the direction to escape sequences to text and paste them. Caf\u00E9 \u2615 \uD83D\uDE00 gives Café ☕ 😀. A surrogate pair is joined into one character.
What is the escape for é?
It is \u00E9 in JavaScript, Java, JSON and Python, \u{E9} in ES6, \E9 followed by a space in CSS, and U+00E9 in code point notation.
Why are some characters shown as two escapes?
Characters above U+FFFF do not fit four hex digits. In the JavaScript notation 1F600 is stored as the pair D83D and DE00.
Does the converter handle every language?
Yes. Any character from U+0000 to U+10FFFF can be escaped, including Chinese, Arabic, Devanagari and emoji. The text of 日本語 takes 9 UTF-8 bytes for 3 characters.
Is my text uploaded anywhere?
No. The conversion is done by the page itself, and the text you paste is not sent to a server.
Sources
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.