ToolJutsu
All tools
Text Tools

Text to Unicode Escape

Convert text into \uXXXX Unicode escape sequences.

Enter text above to see its Unicode escape sequence here.

Processed on your device. We never see your files.

How to use Text to Unicode Escape

What this tool does

Text to Unicode Escape converts any string of text into Unicode escape sequences — the backslash notation used in JavaScript, JSON, CSS, and other languages to represent characters by their hexadecimal code point number. You type or paste text, choose one of three output formats, and the escape sequence appears instantly in the output box. There is nothing to submit and no waiting; the conversion happens character by character in your browser as you type.

The tool offers three formats. The first, \uXXXX, is the classic JavaScript and JSON escape: each character becomes a four-hex-digit sequence, and characters above U+FFFF are split into a surrogate pair of two escapes. The second, \u{XXXX}, is the ES6 code-point syntax: it handles every Unicode character in a single token regardless of how large the code point is, so emoji and rare symbols never need surrogate pairs. The third is CSS notation: each character becomes \XXXX followed by a space, matching exactly what is valid inside a CSS content property or @font-face src declaration.

Why you might need it

Developers reach for this tool in several situations. When you need to embed a non-ASCII character inside a JavaScript string that will be transported as JSON or stored in a plain-text environment that might corrupt Unicode, escaping it as \uXXXX makes the string fully ASCII-safe. CSS developers use the \XXXX format to specify icon glyph codes inside the content property without worrying about file encoding. Security researchers and educators use escape sequences to discuss characters precisely — the escape leaves no ambiguity about which code point is intended, even when rendering environments differ.

The code-point counter under the output box is also useful on its own. If you have a string containing emoji, the code-point count (how many visible characters there are) often differs from the UTF-16 code-unit count (what JavaScript’s .length property returns). Seeing both at once helps you diagnose off-by-one bugs in string length checks.

How to use it

  1. Type or paste your text into the Text to convert box.
  2. Choose the output format with the toggle at the top: \uXXXX for JavaScript/JSON, \u{XXXX} for modern ES6, or CSS \XXXX for stylesheets.
  3. The escape sequence appears in the output box immediately — no button press needed.
  4. Click Copy output to copy the result to your clipboard.
  5. Use Load sample to try a short text that includes an emoji and accented letters, demonstrating surrogate pairs and multi-byte characters.
  6. Click Clear to reset both boxes.

Common pitfalls

The most common confusion is the trailing space in CSS escapes. The CSS spec requires a whitespace character after a hex escape so the parser knows where the code point ends. If you paste a CSS escape into JavaScript you must remove that trailing space, and vice versa.

Surrogate pairs in \uXXXX mode can look alarming if you are not expecting them — a single emoji produces two \uD??? sequences. This is correct UTF-16 encoding. If you only need to support modern JavaScript engines, switch to \u{XXXX} mode and you will get a single clean escape per character, which is also easier to read and audit.

When working with HTML or XML, note that these Unicode escapes are for source code, not markup. If you need to represent a character in HTML, you want an HTML entity like 🌍, not a JavaScript escape. Those formats are not the same thing.

Tips and advanced use

Compare the code-point count with the UTF-16 count at the bottom of the output. A string of pure ASCII characters will show identical numbers. A string with emoji or CJK characters in the supplementary planes will show a lower code-point count than the UTF-16 count, because each of those characters occupies two UTF-16 code units. This tells you instantly whether a JavaScript .length check on that string will give you the number you expect, or whether you need to use spread ([...str].length) instead.

For batch escaping, paste an entire paragraph or code snippet. Every character is escaped, including ASCII, which produces a fully escaped form useful for obfuscation testing or encoding round-trip verification. If you only want to escape non-ASCII characters, you would need to post-process the output in your own code — a valid next step once you have seen the format this tool produces.

Frequently asked questions

Is my text sent to a server when I convert it?
No. The conversion runs entirely inside your browser using JavaScript. Your text never leaves your device — no uploads, no logging, and no third-party requests. You can verify this in your browser's Network tab while using the tool.
What is the difference between the three output formats?
\uXXXX is the classic JavaScript and JSON string escape — four hex digits, and astral characters (emoji, rare symbols) need a pair of surrogates. \u{XXXX} is the ES6 code-point syntax that handles every character in a single token, with no surrogate pairs. The CSS \XXXX format is used inside CSS content values and @font-face declarations; each escape ends with a space to tell the parser where the hex stops.
What are surrogate pairs and why do they appear in the \uXXXX format?
JavaScript strings are encoded as UTF-16, which uses 16-bit code units. Characters above U+FFFF — emoji and many historic scripts — cannot fit in a single 16-bit unit, so they are encoded as two consecutive code units called a surrogate pair. The \uXXXX format mirrors this exactly: you will see two \uD??? escapes back to back for those characters. The ES6 \u{XXXX} format avoids this by encoding the actual code point directly.
Can I use the output directly in my JavaScript or CSS source code?
Yes. Copy the output and paste it into a string literal in your source. For JavaScript, choose \uXXXX or \u{XXXX} depending on which ES version you target. For CSS content properties or @charset declarations, use the CSS \XXXX form. The trailing space in CSS escapes is required by the spec — remove it only if another space would naturally follow.
What happens with emoji or characters outside the Basic Multilingual Plane?
They are handled correctly. The tool iterates your text by Unicode code point (not by UTF-16 code unit), so each emoji or astral character is processed as a single entity. In \uXXXX mode it emits the correct surrogate pair; in \u{XXXX} mode it emits the code point directly. The code-point counter at the bottom shows the real number of characters, not the inflated UTF-16 unit count.

Related tools