Convert text and symbols to/from \uXXXX escape sequences, encode/decode HTML entities (decimal / hex), optionally touching non-ASCII characters only. 100% client-side.
| Term | What it is | Example |
|---|---|---|
| Code point | An abstract character number | U+00E9 = é |
| Encoding | How that number is stored in bytes | UTF-8 uses two bytes: C3 A9 |
| Glyph | What is drawn on screen | Depends on the font |
Unicode defines more than 149,000 code points. UTF-8, UTF-16 and UTF-32 are three ways to serialise them. UTF-8 is dominant on the web because it is byte-order independent, backwards-compatible with ASCII, and self-synchronising, so a corrupted byte damages only a short sequence.
e followed by a combining accent. Both render identically and count differently.length property overcounts them.The fix is to count grapheme clusters — the units a reader perceives — rather than bytes or code units. Use the platform's segmentation API, not a loop over the string.
Because the same character can be composed in different ways, two strings can look identical on screen and compare as unequal. Unicode defines four normal forms to resolve this: NFC (composed) and NFD (decomposed), plus compatibility variants NFKC and NFKD that additionally fold things like ligatures and full-width forms. The practical rule is to normalise user input before comparing, sorting or storing it — otherwise duplicate entries appear that differ only in invisible ways.
Unicode carries a bidirectional algorithm so that right-to-left scripts mix correctly with left-to-right ones, and it separates locale-independent case mapping from locale-specific rules. For example, the Turkish dotless i means that a naive uppercase conversion produces the wrong letter in Turkish. Use a locale-aware library for anything beyond the basics.
The three encodings trade space in different directions, and the difference is large enough to matter for storage and payload limits:
| Character | Code point | UTF-8 | UTF-16 | UTF-32 |
|---|---|---|---|---|
A | U+0041 | 1 | 2 | 4 |
é | U+00E9 | 2 | 2 | 4 |
€ | U+20AC | 3 | 2 | 4 |
中 | U+4E2D | 3 | 2 | 4 |
😀 | U+1F600 | 4 | 4 | 4 |
UTF-8 spends one byte per ASCII character and grows to two, three and four bytes as code points get larger. UTF-16 is flat at two bytes for everything in the basic multilingual plane, which makes it compact for CJK text and wasteful for plain English. UTF-32 is always four bytes — simple to index, four times the size of ASCII in UTF-8.
The practical consequence: a document that is 1 MB of English is roughly 1 MB in UTF-8 but 2 MB in UTF-16, while the same 1 MB of Chinese is near 3 MB in UTF-8 and about 2 MB in UTF-16. Choose per workload rather than per habit, and remember that the byte counts shown by a language runtime usually refer to the string's internal representation, not to what gets written to disk.