Text to Unicode Escape
Convert text into \uXXXX Unicode escape sequences.
Enter text above to see its Unicode escape sequence here.
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
- Type or paste your text into the Text to convert box.
- Choose the output format with the toggle at the top:
\uXXXXfor JavaScript/JSON,\u{XXXX}for modern ES6, or CSS\XXXXfor stylesheets. - The escape sequence appears in the output box immediately — no button press needed.
- Click Copy output to copy the result to your clipboard.
- Use Load sample to try a short text that includes an emoji and accented letters, demonstrating surrogate pairs and multi-byte characters.
- 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?
What is the difference between the three output formats?
What are surrogate pairs and why do they appear in the \uXXXX format?
Can I use the output directly in my JavaScript or CSS source code?
What happens with emoji or characters outside the Basic Multilingual Plane?
Related tools
Unicode to Text
Decode Unicode escape sequences back into text.
Text to Binary
Convert text into binary code.
Binary to Text
Convert 8-bit binary back into readable text.
ASCII Table Reference
Browse the full ASCII character reference table.
Base64 Encoder & Decoder
Encode and decode Base64, with full UTF-8 support.
HTML Encoder & Decoder
Encode and decode HTML entities.