Loading…

Image to Base64

Turn any image into a Base64 text string you can paste straight into your code. Drop in a picture and get a data URI, an HTML img tag, a CSS background rule or a Markdown image, ready to copy or save as a file. This is useful for small icons, email templates, single-file pages and API requests. The Image to Base64 tool works on up to 20 images at once and runs in your browser, so your pictures are never uploaded.

  • Free
  • No sign-up
  • Data URI, HTML, CSS, Markdown
  • No upload, runs in your browser

Last updated

How to use the Image to Base64

  1. Drop your images onto the page, or click to choose them. You can add up to 20.
  2. Click an image in the list to choose which one to encode.
  3. Choose the output format: data URI, Base64 only, HTML image, CSS background or Markdown.
  4. Use Copy to put the text on your clipboard, or Download to save it as a file.

Why use this tool

  • Five output formats, so the text is ready to paste into HTML, CSS, Markdown or an API.
  • Works with JPG, PNG, WebP, GIF, SVG, AVIF, BMP and ICO files.
  • Shows the size before and after, so you can see the cost of embedding.
  • HTML and Markdown output includes your alt text, and the image width and height.
  • Private: images are encoded in your browser and never uploaded.

What is Base64?

Base64 is a way to write binary data, such as the bytes of a picture, using only 64 safe text characters: letters, numbers, plus and slash. Because the result is plain text, it can travel through places that only accept text, such as HTML, CSS, JSON and email.

Base64 is an encoding, not a security feature. Anyone can turn the text back into the image, so do not use it to hide anything.

What is a data URI?

A data URI puts the file inside the address itself. It has the form data:image/png;base64, followed by the encoded text. A browser reads it like a normal image address, but it does not need to download a separate file. You can use it in the src of an image, in a CSS url(), or anywhere else a file address is accepted.

Which output format to choose

FormatLooks likeUse it for
Data URIdata:image/png;base64,iVBOR…Any place that takes an image address.
Base64 onlyiVBOR…APIs, JSON and code that adds its own prefix.
HTML image<img src="data:…" alt="" width="32" height="32">Pasting a picture straight into a page or an email template.
CSS backgroundbackground-image: url("data:…");Small icons and patterns in a stylesheet.
Markdown![alt text](data:…)Readme files and notes that allow inline images.

Base64 makes files bigger

Base64 turns every 3 bytes into 4 characters, so the text is about 33% bigger than the picture. Here are three examples.

Original fileBase64 characters
1 KB (1,024 bytes)1,368
10 KB (10,240 bytes)13,656
100 KB (102,400 bytes)136,536

When embedding an image is a good idea

  • Tiny icons and logos. A few kilobytes saves a separate request, and the picture appears with the page.
  • Single-file pages and demos. One HTML file that shows its pictures and needs no other files.
  • API and JSON data. Many APIs expect an image as a Base64 text field.
  • Email templates. Some email programs show embedded images, but many block them. Test in the programs your readers use.

For large photos, a normal image file is usually the better choice. An embedded picture cannot be cached on its own, and it makes the HTML or CSS file bigger, which can slow down the first view of your page. Compress it first with the Image Compressor if you still want to embed it.

A note about SVG

An SVG image is already text, so you can often put it in a page directly, or in a data URI without Base64, and get a smaller result. The Base64 version is still useful when a system only accepts Base64.

Your images stay on your device

The encoding is done by your browser. Your pictures are not sent to our server, stored or logged. Be careful with where you paste the result, because the Base64 text contains the whole picture.

Image to Base64 FAQ

It turns an image file into a Base64 text string. You can paste that text into code, so the picture is part of the page and no separate file is needed.
Yes. It is free with no sign-up, and the images are encoded in your browser. They are never uploaded or stored.
Choose the HTML image format and paste the result into your page. It is an img tag whose src is a data URI, with your alt text and the image size already added.
Choose CSS background and paste the rule into your stylesheet. It sets background-image to a url() that holds the data URI.
Base64 uses 4 text characters for every 3 bytes of the file, so the text is about 33% bigger.
Only for very small images, where it saves a request. For larger pictures it usually makes the page slower, because the text adds to the file size and cannot be cached on its own.
Base64 is the encoded text. A data URI is that text with a short prefix, such as data:image/png;base64, so a browser knows what the file is.
No. It is just a different way to write the same data. Anyone can decode it, so it does not protect a picture.
Each image can be up to 5 MB, and you can add up to 20 at a time. Very large Base64 text is hard to work with, so keep embedded images small.
Yes, any browser can show a data URI, so paste it into the address bar or into an img tag. This tool only encodes images and does not decode text.