PK Systems
Encoders & decoders

Base64 Image Encoder & Decoder

Convert images to base64 data URLs and back. Drop a file or paste a data URL — never leaves your browser.

Base64 Image Encoder & Decoder

Drag & drop an image, or click to choose Supports PNG, JPG, WebP, GIF and SVG.

tools.base64-image.result.label

What is a base64 data URL?

A data URL packs a small file directly into a string of the form data:<mime>;base64,<payload>. Browsers treat it like any other URL — you can drop one into <img src>, a CSS background-image, or an email signature. Base64 expands the original bytes by ~33%, so it's best for tiny assets (icons, sprites, small avatars). For anything bigger you usually want a regular image file behind a CDN.

How to use this tool

In Encode mode, drop or pick an image and copy whichever flavour you need: full data URL, raw base64 (no prefix) or a ready-made <img> tag. In Decode mode, paste any data URL or raw base64 string and the image renders back in the preview — handy when you find one in someone else's CSS or an exported HTML email and want to see what it actually is. Switch modes with the chip at the top.

When (and when not) to inline images

Good fits: tiny logos and icons that ship in the same HTML/CSS file, signature graphics in transactional emails, embedding an asset in a single-file HTML demo. Bad fits: hero images, photo galleries, anything reused across pages — base64 disables HTTP caching for that asset, blocks parallel image loading, bloats your HTML/CSS payload and hurts Largest Contentful Paint. Rule of thumb: under ~2 KB encoded is usually fine; above that, prefer a normal file.

Common MIME types

The MIME type after data: tells the browser how to decode the payload — getting it wrong (e.g. shipping a JPG as image/png) breaks the image silently in some browsers.

Format MIME type Notes
PNGimage/pngLossless, supports transparency. Best for icons and UI.
JPG / JPEGimage/jpegLossy. Best for photos. No transparency.
WebPimage/webpSmaller than PNG/JPG; supported by all modern browsers.
GIFimage/gifAnimated, 256-colour. Heavier than WebP/MP4 for video.
SVGimage/svg+xmlVector. Prefer URL-encoded over base64 in CSS.

Frequently asked questions

Does the image leave my browser?
No. The file is read with FileReader directly into a data URL string in JavaScript. There is no upload, no server hop, no analytics call carrying the image. You can drag-drop and disconnect from the network — it still works.
Why is the base64 string so much longer than the file?
Base64 represents every 3 bytes of binary as 4 ASCII characters, so the encoded string is roughly 33% longer than the original file. The data URL adds a few more bytes for the data:<mime>;base64, prefix.
Can I embed an SVG without base64?
Yes — and you usually should. SVGs work as plain text inside a data URL with just URL-encoding (data:image/svg+xml;utf8,<svg…>) and stay much smaller than the base64 form. This tool gives you the base64 version for compatibility; for production CSS, prefer the URL-encoded variant.
Will inline images be cached by the browser?
Only as part of the document/CSS that contains them. They cannot be cached individually like a regular image file. If the same icon is inlined into ten pages, each page re-downloads it. That's why inlining only pays off for very small assets used once or twice.
Can I decode an arbitrary base64 string?
Yes — paste it into the box in Decode mode. If it doesn't have a data: prefix, the tool tries to detect the image type from the magic bytes (PNG, JPG, GIF, WebP, SVG). If detection fails, you'll get an "invalid" error and can prepend a data:image/png;base64, prefix manually.
Why does my data URL include line breaks?
Some encoders wrap base64 at column 76 (the MIME standard for email). Browsers tolerate that in <img src> but a few systems don't. This tool always emits the base64 as a single line; if you paste a wrapped string in decode mode, we strip the whitespace before decoding.