Skip to content

Image to Base64

Drop images here

Or paste one with Ctrl+V (Cmd+V on a Mac). PNG, JPG, GIF, WebP, AVIF, SVG, ICO and BMP, up to 10 MB each.
Images stay on your device

Base64

Open or drop an image

You can paste one with Ctrl+V too. You’ll get a data URI, an <img> tag, CSS and the bare Base64, each ready to copy.

Paste Base64 on the left

Bare Base64 or a whole data URI both work. The picture shows up here, ready to download.
Nothing here yet

Image to Base64 Converter – Data URI for HTML and CSS

What Is an Image to Base64 Converter?

It writes a picture out as plain text, so you can paste the picture straight into HTML, CSS or anywhere that only takes text. Open a PNG, JPG, SVG or any common image and you get the text in the shapes people actually use: a data URI, a ready-made <img> tag, a CSS line and the bare Base64. It also works the other way: paste Base64 and get the picture back.

Everything happens in your browser. Your images aren’t uploaded, and the page doesn’t download anything you paste.

Base64 and Data URIs in One Minute

Base64: a file as letters

A picture is bytes, and most bytes can’t be typed. Base64 writes every 3 bytes as 4 safe characters (A to Z, a to z, 0 to 9, + and /), so the whole file fits in a line of text. Every PNG starts the same way: iVBORw0KGgo.

Data URI: Base64 with a label

Put data:image/png;base64, in front and a browser knows what the text is. That’s a data URI, and it goes anywhere a normal image address would: src="" in HTML, url() in CSS.

A whole image in one line of HTML

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMBAMAAACkW0HUAAAAMFBMVEX/ZEf/Y0cAAAD/Y0b/MzP/VTj/aUv//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAvNu7tAAAAEHRSTlP+zAB4BQkRAQAAAAAAAAAAoLetVgAAAExJREFUeNplwbEJgEAMQNGfpDkE4RDsz8YFdJGrLAVHcF4HsLs2KRQH8D07uxZrz5xBDirAaOkGwtz5ywCiBUB1AhjsfRzZbNcWy/UBM5YOmlttFMQAAAAASUVORK5CYII=" alt="Red dot" width="12" height="12">

That’s this tomato-red dot: Red dot The PNG file is 221 bytes, and as Base64 it’s 296 characters, about a third more. No file sits next to the page; the picture is in the tag itself.

How to Use the Image to Base64 Converter

Click Sample in the tool above to follow along with two coffee cups, a PNG and an SVG.

Step 1 Add Your Images

  • Open or drop: click the upload button or drag files onto the tool. You can add up to 20 at once.
  • Paste: copy a picture (right-click it in a browser and pick Copy image, or take a screenshot) and press Ctrl+V, or Cmd+V on a Mac.
  • SVG code works too. Paste the code of an SVG anywhere on the page and it’s added as an image.

Each image shows up in the list on the left. Click one to see its results.

Step 2 Check What You Got

Next to the preview you’ll see the type, the size in pixels, the file size and how long the Base64 is. The type comes from the file itself, not its name, so a photo called logo.png that’s really a JPG still gets image/jpeg. If something’s off, like a file that’s too big for a data URI, a note tells you above the results.

Step 3 Set the Options

  • Alt text goes into the <img> tag. Describe the picture (“Coffee cup”), or leave it empty if it’s only decoration.
  • Width and height adds the image’s size to the tag, so the page doesn’t jump while it loads.
  • 76-character lines breaks the bare Base64 into short lines, which some older systems and file formats want.
  • SVG as (only for SVGs) switches between Base64 and a URL-encoded data URI, which is usually smaller.

Step 4 Copy What You Need

Every result has its own Copy button, and the lime Copy data URI button at the top copies the one people need most. For a big image the boxes only show the start of the text, but Copy always takes all of it.

Step 5 Going the Other Way

Switch to Base64 → Image and paste the text. The picture shows up on the right, with a Download button that uses the right file ending (.png, .jpg, .svg…).

Which Result Goes Where

ResultLooks likeUse it for
Data URIdata:image/png;base64,iVBOR…Anywhere an image address goes: src, url(), a favicon link, an <image> inside an SVG.
<img> tag<img src="data:…" alt="…">Pasting straight into an HTML page or a template.
CSS backgroundbackground-image: url("data:…");Icons and small patterns in a stylesheet.
Base64 onlyiVBORw0KGgoAAAANSUhEUg…Forms and APIs that ask for “the image as Base64”. They add the label themselves.

When a Base64 Image Is Worth It, and When It Isn’t

A data URI saves the browser one trip to the server, which is nice for something tiny. The catch is caching. A normal image file is downloaded once and then reused on every page of your site. A data URI is part of the HTML or CSS it sits in, so it comes along every time that file does, and the browser can’t keep it on its own.

Good uses

  • Small icons, bullets and arrows in CSS, a few hundred bytes to a few KB each.
  • A page that has to be one file: a report you send as an attachment, a saved page for offline use, an example on a code site.
  • A tiny blurred placeholder that shows while the real photo loads.

Better as a normal file

  • Photos and anything over about 100 KB. It gets a third bigger and slows down the page that holds it.
  • A logo used on every page. As a file it’s cached once; as a data URI it’s sent again and again.
  • Emails. Gmail and Outlook on Windows don’t show data: images, so link to a hosted image.

Base64 Images in HTML and CSS

In an <img> tag

<!-- A file next to the page: cached, loaded once -->
<img src="logo.png" alt="Bean & Leaf Café" width="120" height="40">

<!-- The same logo inside the page: no extra request -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…" alt="Bean & Leaf Café" width="120" height="40">

The data URI takes the place of the file name, and everything else stays the same. Keep the alt text and the width and height: the picture inside the tag doesn’t change how a screen reader or the layout treats it.

As a CSS background

.coffee-badge {
  width: 32px;
  height: 32px;
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…");
  background-size: contain;
}

Use double quotes inside url("…"). Base64 never contains quotes, so it’s always safe in there.

Try it: check marks for a list, no image file needed

.packing-list li {
  list-style-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%2316a34a' stroke-width='2.5'/%3E%3C/svg%3E");
}
  • Passport
  • Phone charger
  • Ground coffee for the cabin

That’s the list above, drawn with the CSS rule. The check mark is a small SVG written right into the stylesheet.

SVG Data URIs: You Can Skip the Base64

An SVG is already text, so it doesn’t have to be Base64 at all. A URL-encoded data URI keeps the code as it is and only escapes the characters that would break it: < becomes %3C, > becomes %3E, # becomes %23 and & becomes %26. The quotes around attribute values become single quotes so it fits inside url("…") and src="…". Text in the drawing, its spaces and line breaks stay exactly as they were. It’s usually smaller than Base64, and you can still read and tweak it.

The check mark from above, as SVG code

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M3 8.5l3 3 7-7" fill="none" stroke="#16a34a" stroke-width="2.5"/></svg>

And the same picture both ways:

/* Base64: 214 characters, unreadable */
url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv…")

/* URL-encoded: 173 characters, still readable */
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%2316a34a' stroke-width='2.5'/%3E%3C/svg%3E")

In the tool, pick SVG as: URL-encoded and it tells you how much smaller it is for your file. One thing to watch: an SVG used as an image must have xmlns="http://www.w3.org/2000/svg" on its <svg> tag. SVG copied out of a web page often doesn’t, so the tool adds it for you and says so.

To encode other text for a URL, like a search term or a link inside a link, use the URL Encoder. To turn an SVG into a PNG instead, there’s SVG to PNG.

How to Turn Base64 Back Into an Image

Switch the tool to Base64 → Image and paste what you have. It doesn’t have to be tidy. The tool takes:

If the data is cut off, you’ll see a warning, and usually a picture with a gray or missing bottom part. That almost always means the copy stopped early, so copy it again.

Try it: a CSS line with a picture inside

background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMBAMAAACkW0HUAAAAMFBMVEX/ZEf/Y0cAAAD/Y0b/MzP/VTj/aUv//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAvNu7tAAAAEHRSTlP+zAB4BQkRAQAAAAAAAAAAoLetVgAAAExJREFUeNplwbEJgEAMQNGfpDkE4RDsz8YFdJGrLAVHcF4HsLs2KRQH8D07uxZrz5xBDirAaOkGwtz5ywCiBUB1AhjsfRzZbNcWy/UBM5YOmlttFMQAAAAASUVORK5CYII') no-repeat;

The = padding at the end is missing, and there’s CSS around it. Decode it and you get the tomato dot back as a 12 × 12 PNG.

Base64 on the Command Line and in Code

For a batch of files, or inside a build script, these do the same job.

Mac and Linux

# Linux: Base64 on one line, saved to a text file
base64 -w 0 coffee.png > coffee.txt

# Mac: the same (it's one line already)
base64 -i coffee.png -o coffee.txt

# Mac or Linux: a whole data URI, ready to paste
echo "data:image/png;base64,$(base64 < coffee.png | tr -d '\n')"

# And back again: text to picture
base64 --decode < coffee.txt > coffee.png

Windows PowerShell

# Base64 of a file, straight to the clipboard
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$PWD\coffee.png")) | Set-Clipboard

# Base64 in a text file back to a picture
[IO.File]::WriteAllBytes("$PWD\coffee.png", [Convert]::FromBase64String((Get-Content "$PWD\coffee.txt" -Raw)))

$PWD is the folder you’re in. Without it, .NET looks in a different folder and says it can’t find the file.

JavaScript

// In the browser: a file from <input type="file"> to a data URI
const reader = new FileReader();
reader.onload = () => console.log(reader.result); // "data:image/png;base64,iVBOR…"
reader.readAsDataURL(file);

Python

# Python: print a file as Base64
import base64
with open("coffee.png", "rb") as f:
    print(base64.b64encode(f.read()).decode())

What It Can’t Do

Related Tools and Guides

Frequently Asked Questions

How do I convert an image to Base64?

Open or drop the image on the Image → Base64 side, or copy a picture and press Ctrl+V. You get four results, each with its own Copy button: a data URI, a ready-made <img> tag, a CSS background-image line and the bare Base64. The image is read in your browser and isn’t uploaded anywhere.

What’s the difference between Base64 and a data URI?

Base64 is the image written as plain text, like iVBORw0KGgo… A data URI is that text with a short label in front saying what it is: data:image/png;base64,iVBORw0KGgo… Browsers need the label, so a data URI is what goes in src="" or url(). Bare Base64 is for places that ask for it, like an API field.

How do I use a Base64 image in HTML?

Put the whole data URI where the file name would go: <img src="data:image/png;base64,iVBOR…" alt="Coffee cup" width="64" height="64">. Copy the <img> tag from the tool and it’s already in that shape. Type the alt text in the Alt text box first.

How do I use a Base64 image in CSS?

Use the data URI inside url(), like background-image: url("data:image/png;base64,iVBOR…"); The CSS background box in the tool gives you that line. It works for list bullets (list-style-image), cursors and border-image too.

Why is the Base64 bigger than my image?

Base64 uses 4 characters for every 3 bytes, so the text is about a third bigger than the file. A 30 KB PNG becomes about 40 KB of text. Gzip on the web server wins some of that back, but it’s still bigger than sending the file.

When shouldn’t I use a Base64 image?

For big pictures. A normal image file is cached by the browser and loaded once, while a data URI is part of the HTML or CSS, so it’s downloaded again with every page that has it. It also has to arrive before the page around it can finish. Tiny icons used in one or two places, roughly under 10 KB, are the good cases. A logo on every page is better as a normal file, because it’s cached once. Above about 100 KB the tool warns you.

How do I turn Base64 back into an image?

Switch to Base64 → Image and paste it. Bare Base64, a full data URI or even a whole <img> tag all work. The tool removes line breaks, fixes missing = padding, finds the type from the data itself, shows the picture and gives you a Download button with the right file ending.

Why doesn’t my Base64 image show in an email?

Many email apps don’t show data: images. Gmail removes them and Outlook on Windows blocks them, so the reader sees an empty box. For email, upload the image somewhere and use its normal https:// address in the src.

Should I use Base64 or URL-encoded for an SVG?

Usually URL-encoded. An SVG is already text, so data:image/svg+xml,%3Csvg… only escapes the few characters that need it, while Base64 makes it about a third bigger and unreadable. Pick SVG as: URL-encoded in the tool and it shows how much smaller it is for your file.