Image to Base64

Choose an image and get its Base64 string or a complete data: URI to paste into HTML, CSS or JSON. The image is read in your browser and never uploaded.

0 bytes
0 chars

Everything runs in your browser. Your text and files are never uploaded.

How to convert an image to Base64

  1. Click Choose file in the tool above and pick a PNG, JPG, GIF, WebP, SVG or ICO file.
  2. Keep Output as data: URI ticked to get a string that starts with data:image/png;base64, (or the matching type). Untick it if you only need the Base64 characters, for example for a JSON field.
  3. Click Copy, or Download to save the result as a text file.

Using the result in HTML and CSS

A data URI puts the picture inside your markup, so the browser does not make a separate request for it:

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo" width="48" height="48">
.icon { background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0..."); }

For JSON or an API, send only the part after the comma and store the MIME type in its own field.

When to embed an image as Base64

Base64 makes an image about 33% larger, and an embedded image cannot be cached on its own. That trade is worth it for small, frequently used images: icons, a logo in an email signature, a placeholder, or an image inside a single-file HTML report. For photos and anything over a few dozen kilobytes, a normal image file is usually faster.

Common problems

To turn a Base64 string back into a picture, use Base64 to image. For plain text, go back to the Base64 encoder.

Converting SVG to a data URI

SVG is different from PNG or JPEG: it is a text file of XML, not binary pixels. Base64 still works, and the tool gives you data:image/svg+xml;base64,..., but you have a second option. Because SVG is text, it can go into a data URI with URL encoding instead of Base64, for example data:image/svg+xml,%3Csvg xmlns=.... That version is usually smaller, since Base64 always adds a third to the size while URL encoding only escapes a handful of characters such as <, >, # and quotes.

Base64 is the safer choice when you do not want to think about escaping, for instance when the SVG contains # colour values, quotes inside attributes, or non-ASCII text. A # left unescaped in a URL-encoded data URI is read as the start of a fragment and cuts the image off.

Two more things to check before embedding an SVG. First, make sure the file has an xmlns="http://www.w3.org/2000/svg" attribute on the root element; browsers will not render a data URI SVG without it. Second, if the SVG contains text in Chinese or other non-Latin scripts, keep the file saved as UTF-8. The encoder here reads the file bytes exactly as they are, so a UTF-8 file stays correct, and you can add ;charset=utf-8 after the MIME type if a tool needs it spelled out.

Frequently asked questions

How do I convert an image to Base64?

Click Choose file and select the image. With Output as data: URI ticked, the result is ready to paste into an img src or CSS url(). Untick it to get the bare Base64 string.

Which image formats are supported?

Any file works, because Base64 encodes raw bytes. The data: URI uses the type your browser reports, such as image/png, image/jpeg, image/gif, image/webp or image/svg+xml.

Is there a size limit?

Files up to 20 MB are accepted. In practice, data: URIs are best for small images such as icons and logos; large photos are about 33% bigger in Base64 and are better served as normal files.

Are my images uploaded?

No. The image is read with the browser FileReader API and encoded on your device. Nothing is sent to a server.