How to convert text to Unicode escapes
- Paste your text into the Input box, or press Sample.
- Pick the format your language or file needs: \uXXXX for JavaScript, Java and JSON, \u{…} for modern JavaScript, CSS for
content:values, UTF-8 bytes for C, Python byte strings and debugging, or HTML for web pages. - Choose Decode to turn any mix of escapes back into readable text.
- The Character inspector lists every character with its code point, UTF-8 bytes and UTF-16 units, which is handy for finding invisible characters.
Unicode escape formats by language
The same character, 😀 (U+1F600), written in each format:
| Where | Format | 😀 written as |
|---|---|---|
| JavaScript, JSON, Java, C# | \uXXXX (UTF-16) | 😀 |
| JavaScript (ES6+), Swift, Rust | \u{X} | \u{1F600} |
| Python, C, C++ | \UXXXXXXXX | \U0001F600 |
CSS content | \X | \1F600 |
| HTML | &#…; or &#x…; | 😀 |
| UTF-8 bytes (C, Python bytes, logs) | \xHH | \xF0\x9F\x98\x80 |
| URLs | %HH | %F0%9F%98%80 (use the URL encoder) |
| Unicode charts and docs | U+X | U+1F600 |
Code points, UTF-8 and UTF-16
Unicode gives each character a number called a code point, written U+ followed by hex.
There are room for 1,114,112 code points, and Unicode 16.0 (2024) assigns more than 154,000 characters. An
encoding decides how those numbers are stored as bytes:
| Character | Code point | UTF-8 | UTF-16 |
|---|---|---|---|
| A | U+0041 | 41 (1 byte) | 0041 |
| é | U+00E9 | C3 A9 (2 bytes) | 00E9 |
| € | U+20AC | E2 82 AC (3 bytes) | 20AC |
| 你 | U+4F60 | E4 BD A0 (3 bytes) | 4F60 |
| 😀 | U+1F600 | F0 9F 98 80 (4 bytes) | D83D DE00 (surrogate pair) |
UTF-8 is used by about 98% of websites because plain English text stays one byte per character and it's compatible with ASCII. UTF-16 is used inside JavaScript, Java, C# and Windows, which is why string lengths count an emoji as 2.
Finding hidden characters
Text copied from the web or word processors can carry invisible characters that break code, passwords and CSV imports. Paste it here and check the inspector for these culprits:
U+00A0non-breaking space, which looks like a space but doesn't match one.U+200Bzero-width space andU+200Dzero-width joiner.U+FEFFbyte order mark at the start of a file.U+2018/U+2019andU+201C/U+201Dcurly quotes in place of straight quotes in code.
Comments 0
No comments yet.