Unicode escape encoder — \u, U+, CSS and HTML forms

Paste text and get it back as Unicode escape sequences in the format your language expects, from JavaScript's \uXXXX to Python's \U0001F600, CSS escapes and HTML references.

Live demo · real result from this tool

Escaped

\u0043\u0061\u0066\u00E9\u0020\u2713\u0020\uD83D\uDE00

Processed on your device — nothing is uploaded.

How to use the Unicode encoder

  1. Paste your text into Text.
  2. Pick an Escape format: \uXXXX for JavaScript, JSON and Java; \u{XXXX} for modern JavaScript; \uXXXX / \UXXXXXXXX for Python and C; U+XXXX for code point lists; \XXXX for CSS; or &#xXXXX; and &#NNNN; for HTML.
  3. Tick Escape only non-ASCII characters if plain letters and digits should stay readable.
  4. Copy the Escaped output into your source file.

What it does and when to use it

Source files, logs and config systems do not always handle accented letters, other scripts or emoji safely. Writing them as escapes keeps the file pure ASCII while the program still sees the real characters. Common reasons are a build tool that mangles UTF-8, a Java properties file, a test that must show exactly which character is in a string, or a CSS content: value with a symbol.

Escaping is an encoding, not encryption. Anyone can read the text back with the Unicode decoder. To inspect one character in detail, with its name, category and UTF-8 bytes, use the Unicode character lookup. For HTML references with a choice between every character and only special ones, the numeric HTML entities tool has more options.

How it works

The tool walks through your text one code point at a time, so an emoji is treated as one character even though it is stored as two UTF-16 units. For each code point it writes:

  • \uXXXX: four hex digits; above U+FFFF, the two surrogate halves, each as \uXXXX.
  • \u{XXXX}: the code point in hex inside braces, without padding.
  • Python / C: \uXXXX up to U+FFFF, otherwise \U followed by eight hex digits.
  • U+XXXX: the code point with at least four digits, separated by spaces.
  • CSS: a backslash, the hex code point and one space.
  • HTML: &#x…; with hex or &#…; with decimal.

Hex digits are upper case. The work happens in your browser.

Worked examples

Café ✓ 😀  (\uXXXX)          →  \u0043\u0061\u0066\u00E9\u0020\u2713\u0020\uD83D\uDE00
Café ✓ 😀  (Python / C)      →  \u0043\u0061\u0066\u00E9\u0020\u2713\u0020\U0001F600
naïve 😀   (CSS, non-ASCII)  →  na\EF ve \1F600
Hi 😀      (U+XXXX)          →  U+0048 U+0069 U+0020 U+1F600

Compare the first two: the emoji is a surrogate pair in JavaScript style but a single \U0001F600 in Python. The CSS line shows the escape-only-non-ASCII option and the space that ends each escape.

Limits and tips

  • Characters made of several code points, such as flags, skin-tone emoji or a letter plus a combining accent, become several escapes. That is correct.
  • Line breaks and tabs are escaped as \u000A and \u0009 in the \u formats, not as \n or \t.
  • For a plain list of numeric codes in decimal or binary, the text to ASCII codes tool is simpler.

Frequently asked questions

Why does an emoji turn into two \u escapes?
JavaScript, JSON and Java strings are made of UTF-16 units, and characters above U+FFFF need two of them, called a surrogate pair. 😀 is U+1F600, so it becomes \uD83D\uDE00. Choose the \u{XXXX} format if your code runs in modern JavaScript and you prefer one escape per character.
Why are plain letters escaped too?
By default every character is escaped, which is useful when you want the whole string in a single, unambiguous form. Tick "Escape only non-ASCII characters" to keep letters, digits and punctuation as they are.
Which format should I pick for JSON?
The first one, \uXXXX with surrogate pairs. JSON allows only that form for escapes. The \u{…} and \U forms are not valid JSON.
Why is there a space after each CSS escape?
A CSS escape ends at the first character that is not a hex digit, so a space marks the end. Without it, \E9 followed by the letter e would be read as one longer number. The space after an escape belongs to the escape, not to the text.
Does escaping protect text from code injection?
Not by itself. Unicode escapes are just another way to write the same characters. To make text safe inside HTML, use an HTML encoder that escapes the markup characters.

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