How to use Base64 Encode
- Type or paste text, or switch to File or image and choose or drop a file (up to 25 MB).
- Choose the options you need: URL-safe (- and _ instead of + and /), Wrap at 76 for email, As a data: URL for CSS and HTML.
- Copy the Base64 from the right, or Download it as a .txt file.
- Swap turns the result into the input of the decoder, to check it comes back exactly.
Why use Base64 Encode
UTF-8 done right
Text is encoded as UTF-8 bytes, so Arabic, Urdu, Chinese and emoji decode back exactly, unlike the browser's bare btoa.
Images and files
A PNG, JPEG, PDF, font or any file becomes Base64, with a preview for images and the size the Base64 will have.
data: URLs
One tick gives data:image/png;base64,… ready for a CSS background or an <img> tag.
URL-safe and wrapped
The RFC 4648 URL-safe alphabet without padding for JWTs and links; 76-character lines for MIME email.
About this tool
Base64 writes any bytes as 64 printable characters, so binary data can travel inside text: images in CSS and HTML, attachments in email, keys and tokens in JSON and URLs. It makes data about a third larger, which is why it suits small icons and fonts but not photos. This encoder handles text and files alike and produces the two alphabets in use: the standard one with + and /, and the URL-safe one with - and _ that JWTs, OAuth and file names need.
Text is always encoded as UTF-8, the encoding the web uses, so a message in Arabic or Urdu comes back letter for letter. For files the page reads the bytes on your device and can wrap the result as a data: URL with the right media type. Nothing is uploaded: the conversion runs in the browser, and the page makes no requests while you work.
Frequently asked questions
How do I convert an image to Base64 for CSS?
Switch to File or image, choose the picture, tick As a data: URL and copy. Paste it as url(data:image/png;base64,…) in your CSS or as the src of an <img>.
What is URL-safe Base64?
The same encoding with - instead of + and _ instead of /, and usually no = padding, so the result can sit in a URL or a file name without escaping. JWTs use it.
Why does my Arabic text come back as question marks elsewhere?
Some tools encode the JavaScript string bytes instead of UTF-8. This page encodes UTF-8, and its decoder reads UTF-8, so the text round-trips; make sure the other side decodes as UTF-8 too.
Is there a size limit?
Files up to 25 MB, which makes about 33 MB of Base64. Text has no practical limit.
Is the file uploaded?
No. The file is read by your browser and encoded on your device.
Is it safe to base64 encode online here?
Yes. The encoding runs in your browser, so the text or file you encode is never uploaded.