Unicode Escape Converter: JS, JSON, Python, CSS
Turn text into Unicode escape sequences for JavaScript, JSON, Python, C, Java, CSS or HTML, or unescape them back to text, in your browser. Escape everything or only non-ASCII characters. Nothing is uploaded.
0 characters, 0 bytes
0 characters, 0 bytes
About the Unicode escape converter
This page turns text into Unicode escape sequences and escape sequences back into text for the languages developers use every day. Escapes let you put any character into source code, configuration or a stylesheet using only plain ASCII, which keeps files safe from editors and pipelines that mangle accented letters or emoji. Choose a style, type or paste, and the result appears at once. The conversion runs in your browser, so nothing is uploaded and your text never leaves your device.
How to escape or unescape text
Steps
- String literal is already selected under Representation. Pick the Escape style that matches your language.
- Leave Text to Unicode selected to escape, or choose Unicode to text to turn escapes back into characters.
- Turn on Escape non-ASCII only to keep letters, digits and punctuation readable and escape just the characters outside ASCII.
- Press Copy to take the result, or Swap to check that it decodes back to the original text.
The escape styles
JavaScript
Characters up to U+FFFF become H; characters beyond it use the ES2015 code-point escape, so the grinning face is \u{1F600}.
JSON and Java
Both use four-digit \u escapes only. A character beyond U+FFFF is written as its UTF-16 surrogate pair, 😀, because neither format has a longer escape.
Python, C and C++
Four-digit \u escapes for the Basic Multilingual Plane and eight-digit \U escapes above it, so the emoji is \U0001F600.
CSS
A backslash followed by the hex code point and a space, such as \1F600 . The space ends the escape so that a following letter that looks like a hex digit is not swallowed; it is not part of the text.
HTML
Hexadecimal numeric character references such as 😀. Decoding also accepts decimal references like 😀 and the five basic named entities, &, <, >, " and '.
Decoding escapes
When unescaping, the page reads every escape form of the chosen family, so JavaScript, JSON, Python, C and Java input may mix \u, \U, \u{...} and \x escapes with simple ones like \n, \t, \" and \\. Surrogate pairs written as two escapes are joined into one character. A malformed escape, such as a \u followed by fewer than four hex digits, is reported with its position, and so is any value beyond U+10FFFF or a surrogate without its partner.
Common uses
- Writing non-ASCII strings into JSON fixtures, Java property files or C source that must stay ASCII.
- Reading log output or API responses full of
ésequences. - Adding an icon character to a CSS
contentproperty. - Checking which code points hide inside a string that looks wrong.
Related tools
For code points and UTF-8, UTF-16 or UTF-32 code units, switch the Representation on this page. To see the UTF-8 bytes of text as binary, decimal or hex codes, use Text to Binary. Named HTML entities are covered by the HTML Encoder and Decoder, and percent-encoding for links by the URL Encoder and Decoder.
Open-source credits
The escaping and unescaping logic is implemented in-house in TypeScript, with no third-party library. The escape formats follow ECMA-262 for JavaScript string literals, RFC 8259 for JSON, the Java Language Specification, the Python and ISO C and C++ universal character names, the CSS Syntax Module Level 3 escapes, and the numeric character references of the WHATWG HTML Standard. Surrogate pairs are computed as defined in The Unicode Standard, section 3.9.