Turn an image file into a Base64 string or data URI, right in your browser.
JPG, PNG, GIF, WebP, SVG, BMP, ICO supported
logo_base64.txt.Under the text box you see two numbers. String length is the number of characters in the output. Decoded size is the size of the image data inside the Base64 text, so it should match your file size.
| Setting | The output starts like this | Use it for |
|---|---|---|
| Prefix on (default) | data:image/png;base64,iVBORw0KGgo… |
An <img> src, a CSS url(), or anywhere a URL is expected |
| Prefix off | iVBORw0KGgo… |
JSON APIs and databases that ask for plain Base64 |
| Wrap in <img> tag, prefix on | <img src="data:image/png;base64,…" alt="Encoded image" /> |
Pasting straight into HTML. Change the alt text to describe your image. |
The MIME type in the prefix comes from your browser, based on the file type. If the browser gives none, the tool works it out from the file name or content. A PNG gets image/png, a JPG gets image/jpeg and an SVG gets image/svg+xml. Every PNG starts with iVBORw0KGgo and every JPG with /9j/, which helps you spot the type later.
An <img> tag with only raw Base64 would not show in a browser. So when you turn on the <img> option, the tool turns the prefix on and locks it. When you turn the <img> option off again, your earlier prefix choice comes back.
The tool does not write CSS for you, but the prefixed output drops straight into a rule like this:
.icon-search {
background-image: url("data:image/png;base64,iVBORw0KGgo…");
}
Base64 turns every 3 bytes of the file into 4 text characters. So the text is 4/3 the size of the file. The exact number is 4 × (file bytes ÷ 3, rounded up), plus the prefix.
Example: a 30 KB PNG is 30,720 bytes. 30,720 ÷ 3 = 10,240, and 10,240 × 4 = 40,960 characters. Add the 22 characters of data:image/png;base64, and you get 40,982 characters, about 40 KB of text. The page that holds it gets about 10 KB heavier than a linked file would be.
| Original file | Base64 characters (no prefix) | Extra size |
|---|---|---|
| 1 KB icon (1,024 bytes) | 1,368 | +344 bytes |
| 5 KB graphic (5,120 bytes) | 6,828 | +1.7 KB |
| 30 KB image (30,720 bytes) | 40,960 | +10 KB |
| 200 KB photo | 273,068 (about 267 KB) | +67 KB |
| 2 MB photo | 2,796,204 (about 2.7 MB) | +683 KB |
Gzip or Brotli compression on your web server wins back part of this extra size, but not all of it.
A common rule is to inline only images of a few KB or less. If you do inline a bigger image, shrink it first with Resize Image or Compress Image. This tool encodes the file exactly as it is and does not make it smaller.
SVG files are already text. For SVG icons, Base64 is often not the smallest choice. You can put the SVG code in a data URI after URL-encoding it, for example data:image/svg+xml,%3Csvg …. That is usually shorter than Base64. This tool only makes Base64. You can still use its output for SVG, and it works fine.
With the prefix on, it starts with data:, then the MIME type and ;base64, for example data:image/png;base64,iVBORw0KGgo. With the prefix off, you get only the Base64 characters. You can also wrap the result in an img tag.
About 33 percent. Base64 uses 4 characters for every 3 bytes. A 30 KB image (30,720 bytes) becomes 40,960 characters, or 40,982 with the data:image/png;base64, prefix.
For small icons and simple graphics of a few KB, for single-file HTML pages, and for APIs that take images as text. For photos, large images and images used on many pages, a normal image file is better. The browser can cache it, and the page stays lighter.
Often not. Many email programs, including Gmail, do not show data URI images. For email, link to an image hosted on a server instead.
An img tag needs the data URI prefix, so the tool keeps the prefix on while Wrap in img tag is on. If the image still does not show, check that you copied the whole text, because it is often very long. Also replace the default alt text, Encoded image, with a short description of your picture.
No. Your browser reads the file with the FileReader API and makes the Base64 text on your device. Nothing is sent to a server.