Unicode Escape Sequences Explained
A Unicode escape sequence is a text notation used in source code or data formats to represent a Unicode character by its numeric value.
On this page
Unicode escapes at a glance
| Syntax | Common context | Example for รฉ | Example for ๐ |
|---|---|---|---|
\uXXXX | JavaScript, JSON, Java, Python for BMP values | \u00E9 | Usually surrogate pair |
\u{...} | Modern JavaScript | \u{E9} | \u{1F600} |
\UXXXXXXXX | Python | \U000000E9 | \U0001F600 |
\xXX | Byte or small code-unit escape in some languages | \xE9 may not mean UTF-8 | Not suitable alone |
&#x...; | HTML | é | 😀 |
&#...; | HTML decimal entity | é | 😀 |
\... hexadecimal | CSS | \E9 | \1F600 |
Escape syntax is not the same as UTF-8 bytes. \u00E9 represents the code point U+00E9, while its UTF-8 bytes are C3 A9.
What is a Unicode escape sequence?
An escape sequence is source or data syntax that represents a Unicode character without writing the literal character directly. A parser interprets the escape, and the final in-memory string usually contains the character, not the backslash notation. Escapes are useful for invisible characters, controls, portability, generated data and formats where a literal character would be hard to read or type. Syntax depends on the language or format, and not every language supports every form. Many modern files can contain literal Unicode directly, so escaping is a tool, not a requirement.
Literal character: รฉ
Unicode escape: \u00E9
Unicode code point: U+00E9
UTF-8 bytes: C3 A9For the numeric model, read What Is a Unicode Code Point?, then try Unicode Escape Converter.
Escape sequences vs code points vs bytes
| Concept | Example for รฉ | Meaning |
|---|---|---|
| Character | รฉ | Rendered text |
| Unicode code point | U+00E9 | Numeric Unicode value |
| JavaScript/JSON escape | \u00E9 | Source or data notation |
| HTML entity | é | HTML character reference |
| UTF-8 bytes | C3 A9 | Encoded byte sequence |
| UTF-16 code unit | 00E9 | UTF-16 representation |
A parser converts escape syntax into a code point or string element. An encoder later converts the string into bytes. Writing UTF-8 byte values inside \u is incorrect: \uC3A9 is not the UTF-8 representation of รฉ. Raw byte escapes and Unicode escapes may behave differently. Never copy UTF-8 bytes directly into \uXXXX syntax.
How \uXXXX works
\uXXXX uses exactly four hexadecimal digits in JavaScript and JSON. In those contexts it represents one UTF-16 code unit. BMP characters usually fit in one escape, while values above U+FFFF do not. Supplementary characters need a surrogate pair in formats limited to four-digit escapes. Other languages may use similar syntax with different rules.
A โ U+0041 โ \u0041
รฉ โ U+00E9 โ \u00E9
ะ โ U+0416 โ \u0416
ๅญ โ U+5B57 โ \u5B57Leading zeroes are part of the fixed-width syntax. Hexadecimal digits may be written uppercase or lowercase, depending on style and format rules.
Characters above U+FFFF
The Basic Multilingual Plane ends at U+FFFF. Supplementary code points range from U+10000 to U+10FFFF, so four hexadecimal digits are not enough. Modern syntaxes may support full code-point escapes, while UTF-16-based \uXXXX syntax uses surrogate pairs.
๐
Code point: U+1F600
JavaScript code-point escape:
\u{1F600}
JavaScript/JSON surrogate-pair escapes:
\uD83D\uDE00
Python long Unicode escape:
\U0001F600
HTML hexadecimal reference:
😀All of these can represent the same Unicode character in their valid contexts.
Surrogate-pair escapes explained
UTF-16 represents supplementary code points with two code units. Each code unit can be written as a \uXXXX escape. The first is a high surrogate and the second is a low surrogate. Together they represent one code point; isolated surrogate escapes are not valid Unicode scalar values.
๐ โ U+1F600
High surrogate: D83D
Low surrogate: DE00
Escaped form: \uD83D\uDE00For the underlying representation, read Code Points vs Code Units and UTF-8 vs UTF-16.
Interactive Unicode escape converter
This local converter shows text-to-escape forms, parses common escape syntaxes, reports malformed input and keeps URL percent encoding separate from Unicode escapes.
Unicode escape converter
Convert text to common escape syntaxes or parse escapes back to text with warnings.
Limit: 2,000 UTF-16 code units. Text stays in your browser.
Unicode escapes in JavaScript
JavaScript supports four-digit escapes, modern code-point escapes and surrogate-pair forms. \u{...} requires modern JavaScript syntax. \uXXXX represents UTF-16 code units, so two surrogate escapes may combine into one code point. Escapes are interpreted in string literals and template literals unless raw handling is used.
const letter = "\u00E9";
const emoji = "\u{1F600}";
const sameEmoji = "\uD83D\uDE00";
console.log("\u00E9"); // รฉ
console.log("\u{1F600}"); // ๐
console.log("\uD83D\uDE00"); // ๐
const literal = "\\u00E9";
console.log(literal); // \u00E9The literal string contains six visible ASCII characters rather than รฉ. String.raw preserves backslash sequences differently, which matters in templates and generated source.
Unicode escapes in JSON
JSON strings support \uXXXX. JSON does not support JavaScript's \u{...} syntax. Supplementary characters may be written as surrogate pairs, and literal Unicode characters are also allowed in JSON strings. JSON parsers interpret escapes while parsing, and double-escaped JSON can expose literal \uXXXX.
{
"letter": "\u00E9",
"emoji": "\uD83D\uDE00",
"literal": "\\u00E9"
}After parsing, letter is รฉ, emoji is ๐, and literal contains the text \u00E9. Use JSON Escape and Unescape.
Unicode escapes in Python
Python string literals support \uXXXX for four-digit escapes and \UXXXXXXXX for eight-digit escapes. \xXX is a two-digit hexadecimal escape, not a general full-Unicode form. Raw strings change how backslashes are handled, and bytes literals have different semantics from text strings.
letter = "\u00E9"
emoji = "\U0001F600"
print(letter)
print(emoji)
literal = r"\u00E9"
print(literal)import json
value = json.loads('"\\u00E9"')
print(value)Python's unicode_escape codec is not a universal JSON or JavaScript escape parser. Avoid applying it broadly to arbitrary user text.
Unicode escapes in PHP
Modern PHP supports Unicode code-point escape syntax such as \u{1F600} in double-quoted strings. Single-quoted strings preserve most backslashes literally. JSON escape decoding should use json_decode(), and HTML entities should use HTML-specific functions. PHP strings remain byte sequences containing UTF-8 bytes when source files are UTF-8.
$letter = "\u{00E9}";
$emoji = "\u{1F600}";
echo $letter;
echo $emoji;
$literal = '\u{1F600}';
$value = json_decode(
'"\uD83D\uDE00"',
true,
512,
JSON_THROW_ON_ERROR
);Do not use executable source parsing for user-provided escape strings. json_decode() follows JSON rules, not general PHP source syntax.
Unicode escapes in Java
Java source supports \uXXXX. Supplementary characters require surrogate pairs in ordinary string literals, and Java strings use UTF-16 code units. Literal backslashes require escaping.
String letter = "\u00E9";
String emoji = "\uD83D\uDE00";
String literal = "\\u00E9";Java source-level Unicode escapes are processed early in source translation, so generated source, comments and examples should be handled carefully.
Unicode character references in HTML
HTML uses character references rather than backslash Unicode escapes. Decimal references use &#...;, hexadecimal references use &#x...;, and named entities exist for some characters.
<p>é</p>
<p>é</p>
<p>😀</p>
<p>😀</p>Literal UTF-8 characters are usually clearer in modern HTML. JavaScript \uXXXX syntax is not HTML syntax. Use HTML Entity Encoder and Decoder.
Unicode escapes in CSS
CSS escapes use a backslash followed by one to six hexadecimal digits. A following whitespace may terminate the escape, and that terminator can be consumed. Escapes can appear in strings, identifiers and generated content, but CSS does not use JavaScript escape rules.
.icon::before {
content: "\1F600";
}
.example::before {
content: "\E9 ";
}Unicode escapes in URLs
URLs use percent encoding of bytes, not \uXXXX as standard URL encoding. Unicode input is typically encoded as UTF-8 bytes and then percent encoded. รฉ becomes UTF-8 bytes C3 A9, then %C3%A9. Writing %E9 may imply a legacy byte interpretation, and literal \u00E9 in a URL is usually backslash text unless an application interprets it specially. Use URL Encoder and Decoder.
Control escape sequences
| Escape | Common meaning |
|---|---|
\n | Line feed |
\r | Carriage return |
\t | Tab |
\\ | Literal backslash |
\" | Literal double quote |
\0 | Null in some languages |
\b | Backspace in some contexts |
Meaning depends on the language or format. JSON supports a defined subset. \b in a string is not a regular-expression word boundary, and double escaping is common when text passes through multiple parsers.
Literal escapes vs interpreted escapes
The rendered character รฉ and the literal text \u00E9 are different strings. Literal escape text consists of the characters \, u, 0, 0, E and 9.
const interpreted = "\u00E9";
const literal = "\\u00E9";
console.log(interpreted); // รฉ
console.log(literal); // \u00E9Whether an escape is interpreted depends on the parser, number of escape layers, string literal rules, JSON serialization, template processing, database storage and user interface display.
What is double escaping?
Double escaping happens when a character is escaped once and the backslash is escaped again for another format. After one parsing layer, literal escape text remains. After a second deliberate parser, the character may appear.
{
"value": "\\u00E9"
}After JSON parsing, the value is literal \u00E9. A second Unicode-escape parser would produce รฉ, but that should happen only when the application contract requires it.
Escapes in APIs and databases
APIs may transport literal Unicode or escaped JSON. JSON serializers usually handle escaping automatically, so application code should not manually escape JSON strings before serialization. Manual pre-escaping can cause double escaping. Databases generally store the resulting string, not source-language escape syntax. A stored \u00E9 may be literal text if it was never parsed, while logs may show escaped representations even when the in-memory value is correct.
Unicode string
โ JSON serializer
โ UTF-8 bytes
โ transport
โ JSON parser
โ Unicode stringInspect both the serialized payload and the parsed application value.
Unicode escapes and normalization
Escapes represent code points. Different escape sequences can represent different normalization forms. NFC รฉ may be written as \u00E9, while NFD eฬ may be written as \u0065\u0301. Both may display identically. Escape conversion does not automatically normalize, and normalization may change the escape sequence after conversion. Read Unicode Normalization Explained, NFC vs NFD and use Unicode Normalizer.
Unicode escapes and grapheme clusters
One grapheme cluster may require several escaped code points. Combining sequences, emoji ZWJ sequences, modifiers and variation selectors can all be represented by multiple escapes. Escaping each code point does not break the sequence by itself, but removing or reordering escapes can change rendering.
eฬ
\u0065\u0301
โฅ๏ธ
\u2665\uFE0F
๐จโ๐ฉโ๐งโ๐ฆ
\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}Read What Is a Grapheme Cluster? and inspect sequences with Unicode Sequence Analyzer.
Safe escape parsing
- Identify the syntax family.
- Do not mix JSON, JavaScript, Python and HTML parsers.
- Reject malformed escapes.
- Reject code points above
U+10FFFF. - Reject isolated surrogates in code-point contexts.
- Handle valid surrogate pairs.
- Limit input size.
- Never use executable language evaluation.
- Preserve original text.
- Report ambiguous or literal backslashes.
- Avoid repeated unescaping.
- Test round trips.
Parse data with the parser for its actual format.
Common Unicode escape mistakes
Treating UTF-8 bytes as \u values
C3 A9 is UTF-8 bytes; \u00E9 is the escape for U+00E9.
Using one \uXXXX for a supplementary character
Use surrogate pairs or a supported code-point escape.
Using JavaScript \u{...} inside JSON
JSON does not support that syntax.
Forgetting to escape the backslash
\\u00E9 and \u00E9 produce different values.
Double escaping JSON
Let the serializer handle strings.
Repeatedly unescaping text
This can corrupt legitimate backslashes.
Using executable source parsing to decode escapes
Use a parser for the actual format.
Confusing HTML entities with Unicode escapes
Different parsers and syntax are involved.
Confusing URL percent encoding with \uXXXX
URLs encode bytes.
Treating \xXX as full Unicode
Its meaning is language-specific and limited.
Ignoring isolated surrogates
They are not valid Unicode scalar values.
Assuming escaped text is normalized
Escape representation and normalization are separate.
Converting text to Unicode escapes in JavaScript
function toUnicodeCodePointEscapes(text) {
return [...text]
.map(character => {
const codePoint = character.codePointAt(0);
return `\\u{${codePoint
.toString(16)
.toUpperCase()}}`;
})
.join("");
}
const json = JSON.stringify("Aรฉ๐");JSON.stringify() may leave many Unicode characters literal, which is valid JSON. Do not assume it always emits \uXXXX. A custom escape function should be used only when the output format requires it, and spread iteration handles code points, not grapheme clusters.
Converting text to Unicode escapes in Python
def to_code_point_escapes(text: str) -> str:
parts = []
for character in text:
code_point = ord(character)
if code_point <= 0xFFFF:
parts.append(f"\\u{code_point:04X}")
else:
parts.append(f"\\U{code_point:08X}")
return "".join(parts)import json
escaped = json.dumps(
"Aรฉ๐",
ensure_ascii=True,
)ensure_ascii=True escapes non-ASCII characters. Supplementary characters may be represented according to JSON encoder behavior. unicode_escape output is Python-specific and not necessarily JSON-compatible.
Converting text to Unicode escapes in PHP
function toUnicodeCodePointEscapes(string $text): string
{
$characters = mb_str_split($text, 1, "UTF-8");
$parts = [];
foreach ($characters as $character) {
$codePoint = IntlChar::ord($character);
$parts[] = "\\u{" . strtoupper(dechex($codePoint)) . "}";
}
return implode("", $parts);
}
$json = json_encode("Aรฉ๐", JSON_THROW_ON_ERROR);JSON_UNESCAPED_UNICODE controls whether many Unicode characters remain literal. Both escaped and literal Unicode can be valid JSON. mbstring and intl may be required, and untrusted input should not be concatenated into executable PHP source.
Practical debugging workflow
- Identify the actual format.
- Preserve the original input.
- Determine whether backslashes are literal.
- Count parsing layers.
- Inspect code points.
- Validate escape syntax.
- Check surrogate pairs.
- Decode with the correct parser.
- Compare parsed output.
- Check normalization.
- Re-encode or serialize once.
- Add round-trip tests.
Use Unicode Escape Converter, JSON Escape and Unescape, JavaScript Escape and Unescape, Unicode Character Inspector and Text to Unicode Code Points.
Try these UnicodeNow tools
These tools convert escapes, inspect code points and compare parsed output across common web and code formats.
Unicode Escape Converter
Convert text to and from Unicode escape sequences and numeric entities.
JSON Escape and Unescape
Escape and unescape JSON string content safely.
JavaScript Escape and Unescape
Escape JavaScript string literals and decode JS escape notation without eval.
HTML Entity Encoder and Decoder
Encode and decode HTML named, decimal and hexadecimal entities.
Text to Unicode Code Points
Convert text into U+XXXX Unicode code point notation.
Unicode Code Points to Text
Convert U+XXXX, 0x, and escape-style code points back to text.
Unicode Character Inspector
Inspect each Unicode character, encoding, category, script and normalization form.
Unicode Sequence Analyzer
Analyze code points, grapheme clusters, bytes, scripts and directionality.
URL Encoder and Decoder
Encode and decode URL components, full URLs and form-style strings.
Frequently asked questions
What is a Unicode escape sequence?
A source-code or data-format notation that represents a Unicode character using a numeric value.
What does \u0041 mean?
It represents U+0041, LATIN CAPITAL LETTER A, in formats that support \uXXXX.
What is the difference between U+0041 and \u0041?
U+0041 is Unicode code-point notation; \u0041 is escape syntax used by certain languages and formats.
Is \u00E9 UTF-8?
No. It is a Unicode escape for U+00E9. The UTF-8 bytes are C3 A9.
How do I escape an emoji?
Use a full code-point form such as \u{1F600} where supported, or a surrogate pair such as \uD83D\uDE00 in JSON.
Why does JSON use two escapes for some emoji?
JSON \uXXXX syntax represents UTF-16 code units, so supplementary characters may require a surrogate pair.
Does JSON support \u{1F600}?
No.
What does \\u00E9 mean?
After one escape-processing layer, it usually represents the literal text \u00E9.
Can I decode Unicode escapes with eval()?
No. Use a parser for the actual format.
Are HTML entities Unicode escapes?
They serve a similar representational purpose but use HTML character-reference syntax.
Are URL escapes the same as Unicode escapes?
No. URL percent encoding represents encoded bytes.
Can two escape sequences display the same character?
Yes. Canonically equivalent sequences may display identically while containing different code points.
Does converting to escapes normalize text?
No.
Can an escape represent an invisible character?
Yes. For example, ZERO WIDTH SPACE can be written as \u200B.
Why do logs show \uXXXX instead of the real character?
The logger or serializer may be displaying an escaped representation of the string.
References
- The Unicode Standard
- Unicode glossary
- ECMAScript language specification: string literals
- JSON specification
- RFC 8259: The JavaScript Object Notation Data Interchange Format
- Python lexical analysis: string and bytes literals
- PHP manual: string syntax
- Java Language Specification: Unicode escapes
- HTML character references
- CSS Syntax Module Level 3: escaping
- WHATWG URL Standard
- MDN: JavaScript lexical grammar string literals
- Python documentation: json
- PHP manual: json_encode
- PHP manual: json_decode