1. Home
  2. Images
  3. Image to Base64

Image to Base64

Turn an image into a Base64 data URI and copy it as CSS, HTML or Markdown.

Runs in your browser · No upload

This is a sample SVG. Upload an image to replace it.

File
sample.svg
Type
image/svg+xml
Original size
255 B
Output length
366 chars
Increase
+43.5%
Dimensions
-
SVG encoding
Result
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMiAzMiI+CiAgPHJlY3Qgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIiByeD0iNyIgZmlsbD0iI2ZmNWIxZiIvPgogIDxwYXRoIGQ9Ik05IDE2LjVsNC41IDQuNUwyMyAxMS41IiBmaWxsPSJub25lIiBzdHJva2U9IiMxNTE2MWEiIHN0cm9rZS13aWR0aD0iMy4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+

To turn Base64 back into an image, use Base64 to Image.

How to use

  1. Drop an image here or click to choose one. You can also paste a screenshot directly with Ctrl+V (or Cmd+V).
  2. Choose an Output: a data URI, the raw Base64 string, a CSS background rule, an <img> tag or Markdown.
  3. Copy the result or click Save as .txt.

A sample SVG icon is loaded when the page opens, so you can see what the output looks like. Your images are encoded in your browser and never uploaded to a server.

How Base64 and data URIs work

Base64 represents binary data using 64 characters: A–Z, a–z, 0–9, + and / (RFC 4648). It turns every 3 bytes into 4 characters, so the result is about 33% longer than the original file. Add the prefix data:<type>;base64, and you get a data URI (RFC 2397), which HTML and CSS can use in place of a file URL.

Output Looks like Where it goes
Data URI data:image/png;base64,iVBOR… Anywhere a URL goes: src, url()
Base64 only iVBOR… API request bodies, JSON fields
CSS background background-image: url("data:…"); Stylesheets
<img> tag <img src="data:…" width height alt> HTML pages, email signatures
Markdown ![alt](data:…) READMEs, docs

Examples

  • A 30,000-byte (about 29 KB) PNG becomes 40,000 characters of Base64, a 33.3% increase.
  • A 1,200-byte SVG icon is 1,600 characters in Base64, but URL-encoded it’s usually shorter. SVG is already text (XML), so only a handful of symbols need escaping, such as < → %3C.

Things to keep in mind

  • Use it for small images. Icons, small logos and loading spinners of a few KB are a good fit. Because a data URI lives inside your HTML or CSS, the browser can’t cache the image on its own, and it gets downloaded again whenever that file changes.
  • It doesn’t make files smaller. Base64 is an encoding, not compression. If size matters, compress the image first.
  • Some email clients don’t display data URI images in signatures.

FAQ

Can I turn Base64 back into an image file?

Yes. Paste it into Base64 to Image to detect the format, preview it and save the file. For plain text rather than images, use the Base64 encoder/decoder.

For SVG, should I use Base64 or URL encoding?

URL encoding is usually shorter and stays readable. Choose Base64 if you need to work with very old tools or picky email clients.

Why does the data URI start with a type such as image/png?

The browser needs to know how to read the data. This tool uses the file type reported for your file, and falls back to the file extension if there isn’t one.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.