Base64 Encode and Decode Without Breaking Emoji and Non-English Text
You have probably met Base64 in the wild: an API token, a data URI in an image tag, a long string pasted into a config file, or an email attachment. It looks like random letters, numbers, + and /, often ending in =. Base64 is not magic. It is a way to represent any bytes as plain, safe text characters so they survive places that only handle text — URLs, JSON, emails, config files. Every 3 bytes…
Base64 encoding and decoding are methods to represent bytes as text characters, allowing them to be safely used in text-based systems like URLs, JSON, emails, and config files. The encoding process converts every 3 bytes into 4 characters, making the output about 33% larger than the input.
However, commonly used functions btoa() and atob() in browsers only handle Latin-1 characters. When these functions encounter emoji or non-English text, they either throw an error or corrupt the result. To avoid this issue, it is recommended to first encode the text as UTF-8, then Base64-encode the resulting bytes.
In modern JavaScript, you can safely encode and decode Unicode text using the following code snippets:
1. Encoding: Create a TextEncoder object, encode the string "Hello 🌍", convert the resulting bytes to a binary string, and then Base64-encode the binary string. The encoded result will be "SGVsbG8g8J+MjQ=".
2. Decoding: Base64-decode the encoded string, convert the resulting binary string to an array of bytes, and then decode those bytes using a TextDecoder. The decoded result will be "Hello 🌍".
For quick encoding or decoding, you can use an online tool that processes text in your browser without installing anything. This tool checks for invalid Base64 input, providing clear errors instead of garbled output. It's essential to note that Base64 is not encryption and should not be used to protect passwords or secrets. It's primarily used for transport and compatibility, not security.
BulkTextKit Pro offers a one-time payment option for bulk processing of up to 50 texts at once, along with saved presets and CSV export. The base tool remains free.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.