What mojibake is - why emoji turn into other characters
This article takes about 2 minutes to read.
Mojibake (garbled text) is the phenomenon where a sequence of bytes representing characters is read with a different character encoding from the one used when it was written, so different characters are displayed. With emoji, it appears as a sequence of symbols such as 😀 or as "?".Mojibake itself is a general phenomenon that happens in both Japanese and English text, but here we focus on cases that happen to emoji and lay out how it works and how to tell the patterns apart.
Definition
Inside a computer, characters are stored as sequences of bytes, and when displayed they are turned back into characters following the rules of a character encoding. If the writing side and the reading side use the same rules, the original characters come back, but if they are read with different rules, different characters are assembled from the same bytes. About HTML character encoding declarations, the W3C explains that if you do not specify one, the characters in the content may be misinterpreted. This is the typical case of mojibake.
Many emoji take 4 bytes per character in UTF-8, and because they have that many bytes, they also break down more dramatically when misread.
How it differs from tofu
When an emoji does not appear correctly, the cause depends on whether a square box appears or meaningless characters line up. With tofu, the character itself has arrived correctly, and the font simply has no design for it. With mojibake, the character that arrived has itself changed into a different character.
| Phenomenon | Example of appearance | Cause | Where to fix it |
|---|---|---|---|
| Tofu | □ | The font has no design for it | The font on the displaying device |
| Mojibake | 😀 / ? / � | The bytes were read with a different character encoding, or were lost during saving | Settings for saving and sending (character encoding declarations / database) |
Tofu can sometimes be fixed by updating the device, but with mojibake the data itself has often changed, and it cannot always be restored on the receiving side.
Patterns of mojibake that happen to emoji
About 4 symbols line up
😀 (grinning face) is the 4 bytes F0 9F 98 80 in UTF-8. If you read this with Windows-1252, a 1-byte character encoding that has been used in Europe and North America, each byte becomes a different character and it displays as 😀. If a single emoji has turned into around 4 characters starting with ð, you can assume that UTF-8 data was read with a 1-byte character encoding.
Emoji with a variation selector attached, such as ❤️ (red heart), take the 6 bytes E2 9D A4 EF B8 8F, and the garbled sequence also becomes longer. If the same bytes are read with Shift_JIS, an older Japanese character encoding, they become a different sequence mixing kanji and half-width katakana, and the unreadable parts turn into replacement characters.
Replaced with "?" or disappearing
This is the pattern where characters that cannot be handled are replaced with "?" or discarded during saving or conversion. For example, the MySQL manual says that the character set utf8mb3 handles up to 3 bytes per character and cannot store supplementary characters outside the Basic Multilingual Plane. Because most emoji are supplementary characters, saving them to a database with this setting can cause only the emoji to be lost.
� (the replacement character) appears
The � at U+FFFD is the character put in place when a sequence of bytes that is not valid for that character encoding is read. When you cut a string at a character limit and it breaks in the middle of an emoji's bytes or a surrogate pair, the incomplete part left over can take this form.
Settings to prevent it
The W3C recommends always using UTF-8 as the character encoding, and saving not only the declaration but the file itself in UTF-8. The HTML character encoding declaration <meta charset="utf-8"> must be placed within the first 1024 bytes of the file, and it is best placed right after the opening head tag. A setting in the HTTP header takes precedence over the meta in the document, so when you write both, make them the same value.
If you store emoji in a database, choose a character set that can handle supplementary characters too (utf8mb4 for MySQL). If processing that counts and truncates characters works in units of codepoints rather than bytes, you can prevent the pattern where a cut in the middle of an emoji produces �.
Common misconceptions
- ❌ "Mojibake is a font problem" → ✅ A font problem is tofu. Mojibake is a misreading of the character encoding or a failure in saving
- ❌ "Garbled characters can be fixed on the receiving side" → ✅ Characters replaced with "?" or discarded cannot be restored
- ❌ "Mojibake does not happen with UTF-8" → ✅ If it is read as a different character encoding somewhere along the way, even UTF-8 data gets garbled
Related terms and articles
- UTF-8 - the encoding scheme that represents emoji in 4 bytes
- Tofu - the square box displayed when a font has no design for a character
- Unicode - the standard that assigns common numbers to characters
- Surrogate pair - the mechanism that represents an emoji by splitting it into 2 units in UTF-16
Was this article helpful?