Developer

Unicode code point

The number Unicode gives to a character, written as U+ and hex digits, like U+0041 for A. Code points run from U+0000 to U+10FFFF, and an encoding such as UTF-8 turns each one into bytes.

How to read U+ notation

A code point is written as U+ followed by at least four hex digits. U+0041 is A, U+00E9 is é, U+20AC is € and U+1F600 is 😀. The Unicode code space runs from U+0000 to U+10FFFF, split into 17 planes of 65,536 code points each. Plane 0, the Basic Multilingual Plane, holds the most common characters. The range U+D800 to U+DFFF is reserved for UTF-16 surrogates and never holds a character.

The first 128 code points match ASCII, so A has the same number in both.

A code point isn't always what you see

What a reader sees as one character can be several code points. é can be the single code point U+00E9, or e (U+0065) followed by a combining accent (U+0301). Both look the same. A flag emoji is two code points, and an emoji with a skin tone and a joined symbol, like 👩🏽‍💻, is several. The unit a reader sees is called a grapheme cluster, and it can span many code points.

So length has four honest answers: visible characters, code points, UTF-16 code units and UTF-8 bytes. For 😀 they are 1, 1, 2 and 4. JavaScript's '😀'.length is 2 because it counts UTF-16 units, while [...'😀'].length is 1. Paste any text into the Character Counter to see its code points, UTF-16 units and UTF-8 bytes.

From code point to bytes

A code point is only a number. An encoding decides how it's stored. U+00E9 is the two bytes C3 A9 in UTF-8 and one 16-bit unit, 00E9, in UTF-16. U+1F600 is four bytes in UTF-8 (F0 9F 98 80), and because it's above U+FFFF, a surrogate pair of two units in UTF-16 (D83D DE00). The same text has different byte lengths in different encodings, and reading bytes with the wrong encoding is how mojibake happens.

Work it out yourselfOpen the Character Counter

Sources

Back to the glossary