Toolstia / Image to Base64 converter

Convert an image to Base64

Base64 is a way of writing binary data, such as an image file, as plain text made of letters, digits and a few symbols. Once an image is text, it can sit inside an HTML page, a CSS rule, a JSON file or an email template, with no separate file to load. That is useful for a tiny icon in a stylesheet, a logo in an email, or a self-contained demo page.

This tool reads an image from your device and gives you the Base64 in the form you need. You can choose the full data URI (data:image/png;base64,...), the bare Base64 text, a ready-made CSS background-image rule or an HTML img tag. There is a preview, a copy button and a download as a text file.

The reading happens in your browser using the file reader built into it. The image is not uploaded. It is also encoded exactly as it is, with no re-compression, so what you decode later is the same file.

Drop an image here, or click to choose

JPG, PNG, WebP, GIF or SVG, up to 8 MB. Nothing is uploaded.

How it works

  1. Drop in your image.
  2. Choose the output format.
  3. Copy the result or download it as a text file.

What Base64 is for

Base64 writes a file as plain text. A data URI such as data:image/png;base64,... lets a small picture live inside your HTML or CSS, with no separate file to load.

When it helps

It suits tiny icons, email templates and single-file pages. It adds about one third to the size, and the browser cannot cache it separately, so it is a poor choice for large photos.

The original file is encoded

Your image is encoded exactly as it is, not re-compressed. If the result is too long, shrink the picture first with the image compressor.

The other direction

To turn Base64 text back into readable text, use the Base64 encoder and decoder.

Worked example and size

Base64 turns every 3 bytes into 4 characters, and pads the end with "=" when the length is not a multiple of 3. A 3,000-byte image becomes 4,000 characters of Base64, and a data URI adds a prefix such as data:image/png;base64, which is 22 characters, for a total of 4,022. The page shows this: "icon.png: 2.9 KB becomes 3.9 KB of text."

So the text is about one third larger than the file, plus a little for the prefix and, for the CSS and HTML options, the wrapper. The size shown refers to the output you currently selected, so it changes when you switch format.

The four output formats

"Data URI" is the whole string, which you can paste straight into the src of an image, or into the address bar of a browser to see the picture. "Base64 text only" removes the data:image/...;base64, prefix, which is what some APIs and JSON fields want. "CSS background-image" gives background-image: url("data:..."); and can go into a rule. "HTML img tag" gives an img element with the data URI as its source and an empty alt attribute.

Remember to add a useful alt text to the img tag if the picture carries meaning, for people who use screen readers. Leave it empty only for purely decorative images.

When inline images are a good idea

Inlining saves one network request. For a small icon of a few kilobytes this can be a good trade, especially in an email template or a single-file page that must work with nothing else attached. It also avoids the picture failing to load when a separate file goes missing.

For anything larger, the trade turns bad. The text is a third larger, browsers cannot cache an inlined image apart from the page or stylesheet that holds it, it makes your HTML or CSS slower to download and parse, and a large string is hard to edit. Photos and big banners are better as normal files.

Limits and what is accepted

Files must be images, which the tool checks by their type, and up to 8 MB. Above that, you see a message asking for a smaller image. An 8 MB file would give about 11 million characters, which many editors and browsers handle badly. The drop area mentions JPG, PNG, WebP, GIF and SVG, and any other format your browser knows how to read as an image will normally work.

The data URI is built from the type your browser reports for the file. If the browser cannot identify the type, for example for a file with an unusual extension, the prefix may be generic rather than image/..., and an img tag using it may not display. Rename the file with the correct extension and try again.

Reducing the size first

The tool does not resize or compress. If the output is too long, make the image smaller before converting: reduce its dimensions to the size it will really be shown at, and use the image compressor. For flat icons and logos, SVG is usually the smallest choice, and an SVG can often be used as plain text with no Base64 at all, although encoding it is safe in more situations.

Privacy

The file is read locally and kept only in the open page. Closing the tab discards it. If you paste the result into a public place, such as a forum or a code repository, then of course the image is public with it.

Questions

Is my image uploaded?

No. It is read inside your browser.

Is there a size limit?

Images up to 8 MB are accepted, but anything over a few kilobytes makes very long text.

Does it work with SVG?

Yes. The SVG is encoded as it is.

Which output should I use?

Data URI for an img src, CSS background-image for styles, and Base64 text only if your code adds the prefix itself.

Why is the Base64 text longer than my image file?

The encoding writes 3 bytes of data as 4 characters, so the text is about 33% larger. The tool shows the original size and the output size so you can see the difference.

How do I turn the Base64 back into an image?

If you have the data URI, put it in the src of an img tag or paste it into a browser address bar to see the image, then save it. If you have only the bare Base64 text, add data:image/png;base64, in front, using the right type for your image.

Will an inline image work in every email program?

Support varies between email clients, and some block data URIs. If the email must work everywhere, test it in the clients your readers use, or attach or link the image the usual way.

Does the tool keep a copy of my image?

No. It only holds the file in the open page while you work, and it does not send it to a server. Reloading or closing the page removes it.