Home / Free tools / Images / Image to Base64 Converter

Image to Base64 Converter

Choose a picture to get its Base64 text as a data URI, CSS, HTML or Markdown, or paste Base64 to get the image back. Nothing is uploaded.

Drag and drop an image here, or

Base64 back to an image

Runs in your browser. Nothing you paste or choose is uploaded or stored.

What this image to Base64 converter does

This tool turns a picture into a Base64 text string, and a Base64 string back into a picture. Choose an image and you get the text in the form you need: a full data URI, the bare Base64, a CSS background-image rule, an HTML img tag or a Markdown image. The preview, the size change and the conversion all happen in your browser, so the picture is not uploaded. In the lower box you can paste Base64 or a data URI and get the image back, with a download link.

A data URI places the file inside the text of a page instead of linking to it. Instead of <img src="logo.png">, the page contains <img src="data:image/png;base64,iVBORw0KGgo..."> and the browser needs no extra request to show it.

How it works

Worked example

Take a PNG icon of 300 bytes. Base64 turns it into 400 characters, a rise of 33.3%, and the data URI adds the 22 characters of data:image/png;base64,. The CSS output is background-image: url("data:image/png;base64,..."); and the HTML output is an img tag with the same URI in its src attribute. The tool shows these numbers for your own file in the green message above the result: type, original bytes, characters produced and the percentage increase. The tests for this page convert real PNG, JPEG and WebP files to Base64 and back and check that the bytes are identical.

When inlining helps, and when it hurts

Tips

Convert the format first if the file is large: a PNG photo is often several times bigger than the same photo as a WebP, which you can make with the image converter. If the text will be placed inside a CSS file, remember that the quotes around the URL matter, and that the whole string must stay on one line. A Base64 string that begins with iVBORw0KGgo is a PNG, one that begins with /9j/ is a JPEG, one that begins with R0lGOD is a GIF and one that begins with UklGR is a WebP, which helps you recognise a string you find in code.

Privacy

Your image is read and converted on your own device. It is not uploaded, stored or logged, and the Base64 text is not added to the page address. Decoded pictures are shown from a temporary address that exists only in your browser. More image utilities are listed on the Image tools page.

Questions

What is a data URI?

A data URI holds the content of a file inside the address itself, in the form data:type;base64,text. A browser can show an image from it without fetching another file.

Why is the Base64 text bigger than my image?

Base64 turns every three bytes into four characters, so the text is about 33% larger than the file, plus a few characters for the prefix.

How big an image should I convert?

Inlining makes sense for small images, up to roughly 10 KB. Over 100 KB the tool shows a warning, because the page that holds the text gets slower and the picture cannot be cached separately.

Can I turn Base64 back into an image?

Yes. Paste it, or a full data URI, in the second box. The tool checks that it is an image, shows it and offers a download with the right file extension.

Which image types are supported?

PNG, JPEG, GIF, WebP, BMP, ICO, AVIF and SVG are recognised from their content. Any type your browser can display can be previewed.

Does it work for images in email?

Often not. Many email programs block data URIs, so attach the image or link to a hosted copy for email.

Is my image uploaded?

No. The file is read in your browser and converted there. It is never sent to a server.

Google, Merchant Center, YouTube, LinkedIn, Indeed, Glassdoor and Shopify are trademarks of their owners. Van Born Labs is independent and not affiliated with them. Google's own help pages are the final word on its rules.