UTF-8 Character Encoding Guide
UTF-8 is a variable-length Unicode encoding that stores each code point in one to four bytes. ASCII characters keep their familiar one-byte values, while accented letters, symbols, and emoji use additional bytes.
Typical UTF-8 Byte Lengths
| Character | Code point | UTF-8 bytes | Length |
|---|---|---|---|
| A | U+0041 | 41 | 1 byte |
| é | U+00E9 | C3 A9 | 2 bytes |
| € | U+20AC | E2 82 AC | 3 bytes |
| 😀 | U+1F600 | F0 9F 98 80 | 4 bytes |
Declare UTF-8 in HTML
Place <meta charset="utf-8"> near the beginning of the document head and serve the page with a matching HTTP Content-Type header. Save the source file itself as UTF-8. A declaration cannot repair bytes that were saved using a different encoding.
Why Garbled Text Appears
Mojibake occurs when bytes encoded one way are decoded another way. A common example is UTF-8 bytes interpreted as Windows-1252, producing sequences such as é instead of é. Replacement characters such as � often indicate invalid or lost byte sequences.