Logo

PNG to Base64

Encode a PNG to Base64 with transparency intact — free, instant, nothing uploaded

Upload PNG

Drag & drop or click to upload

PNG, including PNG-8 and animated APNG

Data URL (full)

Includes the MIME type prefix — paste straight into an HTML or CSS src

Upload a file to see the Base64 output…
Raw Base64

The string only, no prefix — for APIs and databases that add their own header

Upload a file to see the Base64 output…
CSS background-image

A finished CSS rule, ready to paste into a stylesheet

Upload a file to see the Base64 output…
HTML <img> tag

Copy this straight into your markup

Upload a file to see the Base64 output…
Your file never leaves this browser. Nothing is uploaded to a server.

Transparency Survives. That Is the Whole Point.

You encode a logo, paste it into your CSS, and it arrives sitting on a white rectangle. The cut-out edge is gone and the design looks broken. That happens when a converter quietly re-saves your file as JPEG. This PNG to Base64 tool never touches your pixels.

We read the file byte for byte, so the alpha channel arrives exactly as it left. Drop a PNG in and the four outputs are ready before you finish reading this sentence.

How to Convert a PNG to Base64 String Output

  1. Optimise first, if you can. A pass through pngquant or oxipng often halves the file.
  2. Drop the PNG in. Drag it onto the box or click to browse.
  3. Check the growth number. The panel shows exactly how much bigger the encoding made it.
  4. Copy the format you need. Data URL, raw string, CSS rule, or HTML tag.

That first step matters more than people expect. Optimisation before encoding is the highest-leverage thing you can do here, because every byte you remove saves roughly 1.33 bytes in the output.

Why PNG to Base64 Keeps the Alpha Channel

PNG stores transparency in a fourth channel alongside red, green, and blue. Every pixel carries an opacity value from fully clear to fully solid.

Base64 is not an image operation at all. It rewrites bytes as text characters, three bytes at a time, and knows nothing about pixels. Because we hand it the original file, the alpha data passes through untouched.

The tools that break transparency do so earlier in the chain. They load your PNG into a canvas element, then export it — and if the export format is JPEG, the alpha channel has nowhere to go. We skip the canvas entirely.

Encoding a photograph instead? A JPG to Base64 converter will give you a far shorter string for the same picture.

Using a PNG Data URL in CSS

The CSS output is a complete declaration. Paste it inside any rule:

.logo {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAA...");
  background-size: contain;
  background-repeat: no-repeat;
}

Inlining like this removes one network request. For an icon that appears on every page, that is a real win on first load.

Here is the downside we always flag: a stylesheet is render-blocking. Every visitor waits for the whole file, including your Base64 payload, before anything paints. Inline small assets only — under a few kilobytes is the sensible ceiling.

Our guide to inline images in CSS and HTML covers the caching trade-off in full.

When PNG Is the Wrong Format to Encode

Three cases where we would tell you to stop and pick something else:

  • Photographs. PNG stores every pixel losslessly, so a camera image balloons. JPEG or WebP will be dramatically smaller.
  • Flat vector artwork. If the original is an icon set or a logo drawn in vector, encode the SVG instead — see the SVG to Base64 encoder.
  • Large hero images. Anything above roughly 10 KB belongs on a CDN with cache headers, not inline.

If the source is the wrong format, convert it before encoding rather than after. Our image format converter handles PNG to WebP, JPEG, and AVIF.

Going Backwards From a String

Already holding an encoded PNG and need the file? The Base64 to PNG decoder takes the string and gives you a downloadable image.

It works even when the data: header is missing, because a PNG payload always begins with the characters iVBORw0KGgo. That signature is enough to identify the format.

For mixed formats, the general image to Base64 converter accepts anything your browser can read.

Frequently Asked Questions

Does encoding a PNG keep the transparent background?

+
Yes, completely. Base64 copies the file byte for byte, and the alpha channel is part of those bytes. Transparency only disappears when a tool converts your PNG to JPEG first, which this one never does.

Why is my PNG string so much longer than a JPEG of the same photo?

+
Because PNG was designed for flat colour, not photographs. It stores every pixel losslessly, so a camera image can run five to twenty times larger than the JPEG version. The Base64 length simply reflects that.

Can I encode an 8-bit indexed PNG, sometimes called PNG-8?

+
Yes, and you should. PNG-8 uses a palette of up to 256 colours instead of full RGB, which often cuts the file size by half or more. The encoder does not care about bit depth — a smaller file just means a shorter string.

What happens to an animated PNG, or APNG?

+
The animation survives, because APNG is still a valid PNG file underneath. Browser support is good in Chrome, Firefox, and Safari. Email clients are another story, so test before you rely on it.

My transparent PNG shows a black box in some email clients. Why?

+
Older clients that do not understand the alpha channel fill it with their default, and that default is often black. We tell our clients to flatten the image onto the real background colour before encoding for email.

Are text chunks inside the PNG, like copyright or software tags, preserved?

+
They are. PNG stores metadata in tEXt and iTXt chunks, and byte-exact encoding carries all of them across. If you want them gone, strip the file first — encoding will not do it for you.

Should I compress the PNG before converting it?

+
Almost always, and it is the single biggest win available here. Tools like pngquant or oxipng routinely cut PNG size by 60 to 70% with no visible change. Every byte you remove first is 1.33 bytes you never have to paste.

Why is my screenshot such a large PNG?

+
Screenshots capture noisy anti-aliased text and subtle gradients, which defeat PNG compression. A full-screen capture at retina resolution can easily hit two megabytes. Crop to the region you actually need before encoding.

Can I use a Base64 PNG as a favicon?

+
Yes, with a link tag pointing at the Data URL. It saves a request on first load, which is genuinely useful. The catch is that some feed readers and older browsers ignore it, so keep a real favicon.ico as a fallback.

Will the same PNG always produce the same Base64 string?

+
With this tool, yes — identical input, identical output, every time. That is not true of converters built on the canvas API, which re-compress the image and can produce a different string on each run.

The Short Version

Optimise the file, drop it in, copy the output. Converting PNG to Base64 preserves transparency here because nothing re-compresses your image along the way.

Keep it to small assets. Icons and logos inline beautifully; photographs and hero images do not.

Related Tools You Might Like

Advertisement