Image Toolkit

Image to Base64 Converter

Convert Images to Data URIs

Turn an image into Base64 text or a data URI, ready to paste into CSS, HTML or JSON. Best for small icons, and done in your browser, so your image is never uploaded.

Drop an image to turn into Base64

PNG, JPG, WebP, AVIF, GIF, SVG or iPhone HEIC. It never leaves your device.

or paste from the clipboard (Ctrl/Cmd+V)

Guide by Ashley Whitehair, web designer at Norwich Website Design

How to convert an image to Base64

  1. Add your image

    Drop a PNG, JPG, WebP, AVIF, GIF or SVG onto the box above, or click it to choose one. iPhone HEIC photos are converted to JPEG first.

  2. Choose an output format

    Pick Raw Base64, Data URI, CSS background-image, HTML img tag or JSON object. You also see how much bigger the Base64 is than the original file.

  3. Copy it into your code

    Press Copy and paste the text where you need it. Press Clear to encode another image.

What Base64 and data URIs are

Base64 writes any file as plain text, using 64 characters: A to Z, a to z, 0 to 9, + and /, with = as padding at the end. Every 3 bytes of the file become 4 characters, so the text is a third bigger than the file.

A data URI puts that text behind a short header saying what kind of file it is. Browsers treat the whole thing as an image’s address, so it works anywhere an image URL does:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

Your file is encoded exactly as it is, byte for byte: nothing is resized or compressed again.

The five output formats

FormatWhat you getUse it for
Raw Base64The encoded text only, with no data: headerAPIs, JSON fields and databases that ask for a Base64 string.
Data URIThe encoded text behind its data:image/…;base64, headerAnywhere an image address goes: an img src, a CSS url(), a Markdown image or a JavaScript variable.
CSS background-imageA CSS declaration containing the data URIIcons and small backgrounds in a stylesheet.
HTML img tagAn img element with the data URI as its src and the file name as its alt textPages and templates. Replace the alt text with a description of the image.
JSON objectThe file name, MIME type, size in bytes and data URITest fixtures, config files and sending an image to an API.

To go the other way, choose Base64 to image at the top of the tool: paste Base64 or a data URI and download the image it contains. There’s more on that in the Base64 to image guide.

Using the output in your code

In CSS, give the element a size, because a background image doesn’t set one:

.icon {
  width: 32px;
  height: 32px;
  background-image: url('data:image/png;base64,iVBORw0KGgo...');
}

In HTML, set the width and height too, and write alt text that describes the image:

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Company logo" width="32" height="32">

In JavaScript, fetch() turns a data URI back into a Blob you can upload, and in Node.js, Buffer turns Raw Base64 back into the file:

// Browser: data URI to Blob
const blob = await (await fetch(dataUri)).blob();

// Node.js: Raw Base64 to a file
import { writeFileSync } from 'node:fs';
writeFileSync('logo.png', Buffer.from(base64, 'base64'));

When inlining helps, and when it hurts

A data URI saves a separate download, but makes the image bigger and ties it to the file it’s in. It’s worth it for:

  • Tiny icons and graphics, a few kilobytes at most, where saving a request matters more than the extra third.
  • Single-file HTML, such as reports, prototypes and offline pages that must work without separate image files.
  • Emails, where a small image travels inside the message. Support varies between email apps, and Gmail cuts off messages over about 102 KB, so keep images tiny and send yourself a test.
  • Code that needs an image as text, such as JSON APIs and test fixtures.

Avoid it for photos and anything larger:

  • It’s a third bigger. A 192 KB photo becomes 257 KB of text. The gzip or Brotli compression most web servers use wins much of that back in transfer, but the browser still handles the full text.
  • It can’t be cached on its own. A normal image file is downloaded once and reused by every page. An inlined one comes again with every page or stylesheet that contains it, and changing it means downloading the whole file again.
  • It can delay the page. Browsers wait for stylesheets before showing a page, so big data URIs in CSS hold everything up.
  • Lazy loading can’t help, because the image arrives with the HTML.

For bigger images, compress or resize them and serve them as normal files.

Your image never leaves your device

The Base64 text is made by your browser, on your own device, so your image is never uploaded. That matters for unreleased designs and client work.

You can check this yourself: open your browser’s developer tools, watch the Network tab and add an image. The only requests are the page’s own files and anonymous page-view counts, described in our privacy policy. After your first visit, the converter works offline too.

Frequently asked questions

Is this image to Base64 converter free?

Yes. There’s no sign-up and no limit on how many images you encode.

How much bigger does Base64 make an image?

A third: every 3 bytes become 4 characters. The data: header adds about 22 characters more, so tiny files show a higher percentage; a 205-byte icon comes out 45% larger.

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

Base64 is the encoded text on its own. A data URI adds a header saying what the file is, such as data:image/png;base64, so a browser can use it as an image address. Raw Base64 gives you the first and Data URI the second; the CSS, HTML and JSON formats contain a data URI too.

Can I convert Base64 back to an image?

Yes. Choose Base64 to image at the top of the tool and paste the text: raw Base64, a data URI, or even a whole CSS or HTML snippet. You see the image and its format, and can download it. See the Base64 to image guide.

Is there a file size limit?

There’s no fixed limit, and large photos work, but Base64 is meant for small images. Anything over a few kilobytes is usually better as a normal image file.

Which image formats can I convert?

PNG, JPEG, WebP, AVIF, GIF, SVG and other image files are encoded exactly as they are. iPhone HEIC photos are converted to JPEG first, because most browsers can’t display HEIC.

Should I Base64-encode SVG files?

You can, and it works everywhere, but SVG is already text: you can paste the svg element straight into HTML, or use a URL-encoded data URI, which can be smaller. Either way, shrink it with the SVG Cleaner first.

Why does the HTML img tag use the file name as alt text?

It’s a placeholder. Replace it with a short description of the image, or alt="" if the image is only decoration, so screen readers handle it properly.

Do Base64 images work in emails?

In many email apps, but not all. Keep them small, since Gmail cuts off messages over about 102 KB, and send yourself a test before sending to your list.

Is my image uploaded to a server?

No. It’s encoded in your browser, on your device, which is also why the converter works offline after your first visit.