How to URL Encode UTF-8 Characters
Part of the Encoding Toolkitone %XX group per UTF-8 byte β 2 to 4 groups per non-ASCII character
| Character | Encoded | |
|---|---|---|
| Γ© | %C3%A9 | 2 UTF-8 bytes |
| β¬ | %E2%82%AC | 3 UTF-8 bytes |
| ζ± | %E6%9D%B1 | 3 UTF-8 bytes |
| π | %F0%9F%98%80 | 4 UTF-8 bytes |
Explanation
Percent-encoding works on bytes, not characters. A non-ASCII character is first represented as UTF-8 β 2 to 4 bytes, depending on the character β and each of those bytes becomes its own %XX group. That's why one accented letter or emoji can expand into two, three, or four %XX groups instead of one.
Plain ASCII characters (letters, digits, common punctuation) are a single UTF-8 byte each, which is why they mostly pass through unchanged β only the non-ASCII characters in a string actually expand.
See URL Encoding Explained for the full mechanism, or check any character's exact byte breakdown with Unicode Converter.
Valid examples
caf%C3%A9"cafΓ©" β only the Γ© is encoded; c, a, and f are single-byte ASCII and pass through unchanged.
%E6%9D%B1%E4%BA%AC"ζ±δΊ¬" β both characters are 3-byte CJK, giving six %XX groups total.
%F0%9F%98%80"π" β a 4-byte emoji, encoded as four %XX groups.
Invalid examples
%E6%9DA truncated multi-byte sequence β the third byte of a 3-byte character is missing, and decoding it throws "URI malformed" instead of producing a character.
%25E6%259D%25B1Double-encoded β the % from each byte's encoding got encoded again on a second pass.