Convert PNG to Base64
PNG (Portable Network Graphics) is the standard format for images that require transparency or lossless compression: icons, logos, UI elements, screenshots, and graphics with text. This tool encodes PNG files to Base64 strings suitable for embedding in HTML, CSS, or API payloads.
How to Use
- Drop a PNG file onto the upload area or click to browse
- The image is read locally and encoded to Base64
- Select your output format: plain Base64, data URI, or CSS background
- Copy the result
Why PNG for Base64 Embedding
PNG is the natural choice for Base64 embedded images in several scenarios:
Transparency
PNG supports full alpha channel transparency. When you embed a logo or icon as a Base64 data URI, the transparency is preserved. JPEG does not support transparency at all, so any image that needs a transparent background must use PNG (or SVG/WebP).
Lossless quality
Screenshots, diagrams, and images with sharp text edges look better in PNG than JPEG because PNG’s lossless compression preserves every pixel. JPEG’s lossy compression introduces artifacts around sharp edges, especially visible in text and line art.
Small graphics
PNG with palette optimization can produce very small files for simple graphics. A 16x16 favicon might be 400 bytes as a PNG, well under the threshold where Base64 embedding makes sense.
PNG File Size and Base64 Output
PNG files vary enormously in size depending on content:
| Image type | Typical PNG size | Base64 output |
|---|---|---|
| 16x16 icon | 0.3-1 KB | 0.4-1.3 KB |
| 32x32 favicon | 1-3 KB | 1.3-4 KB |
| 200x200 logo | 5-30 KB | 6.7-40 KB |
| 1920x1080 screenshot | 500 KB-3 MB | 667 KB-4 MB |
For the icon and favicon sizes, inlining as Base64 is almost always the right choice. For logos, it depends on how many pages use the image (caching vs. request overhead). For screenshots, serve them as separate files.
Optimizing before encoding
Run your PNG through an optimizer (pngquant, optipng, or tinypng) before Base64 encoding. A well optimized PNG can be 50-80% smaller than the original, which directly reduces the Base64 output size.
PNG Base64 in CSS Sprites
Before HTTP/2 made parallel requests cheap, developers combined multiple small images into a single sprite sheet. With Base64, you can achieve a similar result by inlining each small image directly in CSS:
.icon-home {
background-image: url(data:image/png;base64,iVBOR...);
width: 16px;
height: 16px;
}
.icon-settings {
background-image: url(data:image/png;base64,iVBOR...);
width: 16px;
height: 16px;
}
This trades CSS file size for zero image requests. With gzip compression, the CSS overhead is partially offset. For modern projects, inline SVGs or icon fonts are usually better than Base64 PNGs for icon systems, but Base64 PNGs remain useful for raster graphics that cannot be vectorized.
Data URI Syntax
The data URI for a PNG follows this structure:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
The image/png MIME type tells the browser to decode the Base64 payload as a PNG image. This works in <img> tags, CSS url() values, Canvas drawImage(), and most contexts where a URL is expected.
For other formats, see JPG to Base64, SVG to Base64, WebP to Base64, or the general Image to Base64 converter. To reverse the process, use Base64 to Image.