Unicode code points, UTF-16, and escape notation
Unicode assigns each abstract character a number called a code point. Human-readable notation writes that number as U+ followed by hexadecimal digits, such as U+0041 for A or U+1F600 for the grinning face emoji. A code point is not the same thing as a UTF-8 byte sequence, and it is not always the same as one JavaScript string index.
JavaScript strings use UTF-16 code units. Values in the Basic Multilingual Plane usually occupy one 16-bit unit and can be written as a four-digit escape such as \u4F60. A supplementary code point above U+FFFF occupies a surrogate pair, so U+1F600 becomes \uD83D\uDE00 in fixed four-digit notation. Modern braced syntax, \u{1F600}, writes the scalar value directly and avoids manual pair calculation.
This tool separates representation from execution. It recognizes only U+ tokens, \uXXXX escapes, and \u{…} escapes according to a strict grammar. It never passes the input to eval, Function, a script element, or a JSON parser as executable code. That makes it appropriate for inspecting copied escapes, although the decoded text itself should still be escaped correctly when inserted into HTML, URLs, SQL, or another context.
How to escape and unescape Unicode text
- Choose Encode and enter ordinary text when you want to inspect its Unicode representation.
- Select U+ code points for documentation, braced \u{…} escapes for scalar-oriented JavaScript notation, or \uXXXX for UTF-16 code units and explicit surrogate pairs.
- Choose Decode when you have notation. Enter a list of U+ tokens or a sequence of supported escapes; whitespace between escape sequences is allowed.
- Read any surrogate or range error instead of forcing output. Invalid pairs are not repaired automatically because that would change the original data.
- Copy the resulting text or notation, then apply the escaping rules required by the destination context. Unicode unescaping alone is not HTML, JSON, or URL sanitization.
Unicode code point and escape examples
The same character can have a scalar code point, a braced escape, or one or two four-digit UTF-16 escapes. These examples make the distinction visible without executing the input.
| Input | Output | Conversion direction | Notes |
|---|---|---|---|
A |
U+0041 |
Encode | ASCII code point. Basic Latin characters have one code point and one UTF-16 code unit. |
😀 |
U+1F600 |
Encode | Emoji code point. The emoji is one Unicode scalar value above the Basic Multilingual Plane. |
😀 |
\u{1F600} |
Encode | Braced escape. ECMAScript braced notation can write the full scalar value directly. |
😀 |
\uD83D\uDE00 |
Encode | UTF-16 surrogate pair. Four-digit escape syntax represents the same emoji with a high and low surrogate code unit. |
U+4F60 U+597D |
你好 |
Decode | Decode Chinese code points. Code point tokens may be separated by spaces or commas. |
\u0041\u{1F600} |
A😀 |
Decode | Mixed escape forms. The strict parser can combine supported escape forms but rejects unrelated source code. |
Supported notation and Unicode scalar rules
Code point input must consist entirely of U+ followed by one to six hexadecimal digits, with tokens separated by whitespace or commas. Values must be between U+0000 and U+10FFFF and must not fall in the surrogate range U+D800 through U+DFFF, because surrogate code points are not Unicode scalar values.
Escape input may contain four-digit \uXXXX code units and one-to-six-digit braced \u{…} scalar escapes. A high surrogate in four-digit form must be followed immediately, apart from ignored whitespace, by a low surrogate. A low surrogate cannot appear alone.
- Hexadecimal input is case-insensitive; output uses uppercase hexadecimal for readability.
- Braced escapes represent scalar values directly and reject surrogate-range values.
- Four-digit escapes represent UTF-16 code units, so supplementary characters require two escapes.
- Unpaired surrogates in ordinary input text are rejected rather than replaced.
- Source-code fragments, quoted strings, concatenation, and function calls are outside the accepted grammar.
How surrogate pairs are calculated and validated
For text-to-code-point output, the converter iterates Unicode characters rather than individual UTF-16 indexes. JavaScript’s code-point-aware iteration combines a valid high and low surrogate into one scalar value. The hexadecimal number is then formatted as U+ notation or placed inside braces.
For fixed \uXXXX output, the converter intentionally iterates UTF-16 code units. A supplementary scalar value has 0x10000 subtracted from it; the upper ten bits are added to 0xD800 for the high surrogate and the lower ten bits are added to 0xDC00 for the low surrogate. JavaScript already stores that pair, so formatting each code unit reveals the correct two escapes.
During decoding, braced values and U+ tokens pass through scalar-range validation before String.fromCodePoint is used. Four-digit escapes are parsed as code units and scanned in order. High surrogates must pair with following low surrogates, and lone lows are rejected. No parser branch interprets backslash sequences such as \x, octal escapes, template substitutions, or JavaScript expressions.
When Unicode notation is useful
Unicode notation helps explain what text contains when visual appearance is ambiguous. It is a diagnostic and documentation technique, not a universal escaping strategy.
| Item | Description |
|---|---|
| Debugging emoji and supplementary text | See whether a system stores one scalar value correctly or splits, truncates, or misorders a surrogate pair. |
| Inspecting invisible characters | Code point output can reveal non-breaking spaces, zero-width characters, controls, and separators that look like ordinary spacing. |
| Writing technical documentation | U+ notation identifies a character independently of font, source encoding, or programming-language syntax. |
| Reviewing escaped API data | Decode copied Unicode escapes before investigating higher-level JSON or application behavior, without running the text as code. |
| Comparing normalization results | Two visually identical strings may contain a precomposed character or a base letter plus combining marks; code points make the sequence visible. |
Unicode errors and security boundaries
An invalid surrogate is not merely a display problem. It is an ill-formed UTF-16 sequence, and different encoders may replace it, reject it, or preserve the raw unit. This tool rejects it so the user can see that the source is malformed rather than unknowingly converting U+FFFD.
Decoding an escape does not make the result safe for a destination. A decoded < character can become HTML markup, a percent sign can affect a URL parser, and quotes can matter in JSON or SQL. Apply context-specific output encoding after Unicode conversion.
- U+110000 is above the maximum Unicode code point and is invalid.
- U+D800 is not a scalar value even though it fits in four hexadecimal digits.
- \uD83D without a following low surrogate is rejected.
- \u{XYZ} contains non-hexadecimal digits and is rejected.
- Text such as alert(1) is not treated as an escape and is never executed.
Unicode escaping compared with JSON, HTML, and URL encoding
Unicode escape notation identifies characters or UTF-16 units. JSON strings use a related \uXXXX syntax but also define quotes, backslash escapes, and a complete document grammar. HTML entities and URL percent-encoding solve context-specific syntax problems with different representations.
UTF-8 byte inspection is another distinct layer. The emoji U+1F600 becomes four UTF-8 bytes F0 9F 98 80, two UTF-16 code units D83D DE00, or one scalar code point 1F600. None of those forms is more correct in isolation; the correct form depends on the protocol being examined.
| Item | Description |
|---|---|
| JSON escaping | Requires a full JSON parser and string grammar. This tool parses only explicit Unicode notation and does not parse documents. |
| HTML entities | Protect or represent characters in HTML text. They use forms such as & and 😀 rather than JavaScript escapes. |
| UTF-8 bytes | Represent code points for storage and transport. One code point can require one to four bytes. |