Image to Base64

Encode an image to a Base64 data URI — ready to paste into CSS or HTML. Runs in your browser.

or drag & drop

In your browser · No upload

How to convert an image to Base64

Drop an image and cutbg encodes it to a Base64 data URI you can copy straight into your CSS background-image, an img src, or a JSON payload — no upload, all on your device.

Is my image uploaded?

No — the encoding happens in your browser; the image never leaves your device.

Image to Base64 data URI, with the real size cost and copy-paste snippets

What you get

Drop an image and the box fills with a complete data URI, ready to paste:

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

It has three parts:

  • data: tells the browser the image is inline, not at a URL.
  • image/png is the file's MIME type, taken from the file itself: image/jpeg, image/webp, image/svg+xml, image/gif and so on.
  • ;base64, is followed by the file's bytes, encoded as text.

The file isn't re-compressed, resized or cleaned. The Base64 is an exact copy of the bytes you dropped, so any metadata in it, GPS included, is still inside the string. If that matters, run the image through Remove metadata first.

There's one exception. An iPhone HEIC photo is converted to JPG first in Chrome, Firefox and Edge, so you get data:image/jpeg. Safari reads HEIC natively and encodes it as-is, giving data:image/heic, which only Safari can display. Convert it with HEIC to JPG first if the string will be used anywhere else.

The size shown above the box (Base64 · 12.4 KB) is the length of the whole string, prefix included, in kilobytes of text.

Need only the raw Base64?

Many APIs and JSON fields want just the encoded part, without the data:...;base64, prefix. Delete everything up to and including the first comma. In JavaScript: uri.split(',')[1].

How much bigger it gets

Base64 turns every 3 bytes into 4 characters, so the text is 33% larger than the file, plus a few dozen characters of prefix. We checked on real files:

File Original Base64 text Base64 after gzip
Photo, JPG 49.0 KB 65.4 KB (+33%) 48.4 KB
Same photo, PNG 190.8 KB 254.3 KB (+33%) 191.4 KB
Logo, SVG 403 bytes 540 bytes (+34%) 333 bytes

The last column is the surprise. If your server compresses HTML and CSS with gzip or Brotli, as most do, the extra 33% mostly disappears on the wire for JPG and PNG. Base64 has only 64 symbols, and the compressor squeezes the waste back out.

So the transfer size isn't the main cost. These are:

  • No separate caching. An image file is downloaded once and cached. An inline image is downloaded again with every copy of the HTML or CSS that contains it, and if the same icon appears on 50 pages, it's in all 50.
  • It blocks the page. A stylesheet must download fully before the page renders, so a 200 KB background inlined into CSS delays everything, not just the image.
  • It's harder to maintain. You can't swap the image without editing the code, and diffs fill up with unreadable text.

When inlining makes sense

  • Small icons and UI sprites under a few KB, used on one page or in one component. Saving a request is worth more than the bytes.
  • A single self-contained HTML file that has to work offline or be sent as one attachment: a report, a demo, a mockup.
  • Placeholders. A tiny blurred preview shown while the real image loads.
  • Test fixtures and code samples, where an external file would be a hassle.
  • JSON or API payloads that accept images only as text.

When not to

  • Photos and anything over roughly 10 to 20 KB. Serve them as files, with loading="lazy" and proper caching.
  • Images used on many pages. Caching wins.
  • Email newsletters, without testing first. Support for data-URI images in email clients has varied a lot, and the most-cited compatibility tests (caniemail.com) date back to 2020. Hosted images or CID attachments are the usual choice. If you do inline, check the result in Gmail, Outlook and Apple Mail before you send.
  • Social share images (og:image). Social networks need a real URL to fetch.

Copy-paste snippets

HTML:

<img src="data:image/png;base64,iVBORw0KGgo..." width="24" height="24" alt="Settings">

Always set width and height. The browser can't know the size before decoding, and the page jumps when it does.

CSS background:

.icon-search {
  background: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...") no-repeat center / 16px 16px;
}

Favicon without a file:

<link rel="icon" href="data:image/png;base64,iVBORw0KGgo...">

For a real site, a proper set of icon files works better. Favicon generator makes them.

Markdown: ![logo](data:image/png;base64,...). Some renderers show it and some strip it for security, so preview it where it will actually be read.

SVG: skip Base64 if you can

SVG is already text, so encoding it to Base64 only makes it bigger. Percent-encode the few characters that break a URL instead:

background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E...%3C/svg%3E");

Swap double quotes inside the SVG for single quotes, and encode <, >, # and %. Our 403-byte logo came out at 465 characters this way, against 540 as Base64. After gzip it was 238 bytes, against 333. This tool only produces Base64, so do that step by hand or with a build tool.

Make the image small first

Since the string grows with the file, shrink the image before encoding. Resize it to the exact size you'll display with Resize image, then run it through Compress image. A 512 px icon shown at 24 px carries about 450 times more pixels than anyone will see.

Related tools

Frequently asked questions

What is a Base64 data URI?
A text encoding of your image you can paste directly into CSS or HTML, so the image loads with no separate file or request.
Which formats can I encode?
Any image the browser can read — PNG, JPG, WebP, GIF, SVG and more. The data URI keeps the original format.
Is my image uploaded?
No — the file is read and encoded locally in your browser; it never leaves your device.