Developer / Free browser tool
Image to Base64 Converter
One page, both directions: a file becomes a data URI with ready-to-paste CSS and HTML, or a pasted string becomes an image again. The declared type is never trusted over the bytes.
No account or install. Tool input is processed on your device.
That file could not be read.
That file is large; the data URI will be very long.
—
0 characters
A data URI is about a third larger than the file. Copy and download always use the complete string, even when the preview is shortened.
Whitespace is ignored. The image format is read from the decoded bytes, and the decoded size is capped at 25 MB.
That string could not be decoded.
The header and the bytes disagree.
Your decoded image appears here. The bytes never leave the tab.
About this tool
A data URI packs a whole image into a string: the media type, a base64 marker, then the file itself. It is how a small icon gets into a stylesheet without a second request, and how a test fixture travels inside a JSON file. This page produces that string and reads one back.
The encoder accepts PNG, JPEG, WebP and GIF. It reads the file, identifies the format from the first bytes rather than the extension, measures the image, and shows the data URI with a CSS background-image declaration and an HTML img tag. Files above 8 MB still convert, with a warning that the string is larger than most style sheets should carry.
The decoder takes a data URI or bare Base64, strips whitespace, validates the alphabet and inspects the decoded bytes before showing anything. The declared media type is ignored, so a PNG mislabeled as a JPEG still opens as a PNG. SVG is rejected in both directions: an SVG data URI can carry script.
Why the bytes decide the format
The media type in a data URI is a claim, not a fact. Files get renamed, APIs return the wrong header, and a paste can carry a header from another file. The decoder checks the signature instead: the eight-byte PNG header, the JPEG start-of-image marker, the GIF87a or GIF89a label, or the RIFF container ending in WEBP. The download extension comes from that check, not from the text before the comma.
Size is checked before decoding, too. Base64 length translates to bytes closely enough to reject a 30 MB payload before it allocates one, and the decoded image is capped at 25 MB.
The real cost of inlining an image
Base64 uses four characters for every three bytes, so the string is 33 percent larger than the file before compression. An 8 MB photo becomes about 10.7 MB of text, and it cannot be cached separately, lazy-loaded, or compressed as well as the binary. Small assets are the exception: a 2 KB icon inlined into a style sheet removes a request, which matters on a high-latency connection. A few kilobytes is safe; a few hundred usually is not.
What happens to your file
Nothing leaves the tab. The file is read with FileReader, converted with browser APIs and rendered from a local blob URL. There is no upload endpoint and no analytics call in the conversion path. When you replace a decoded preview, the previous blob URL is revoked so the memory can be reclaimed.
Base64 makes an image about a third larger before document compression. A data URI can avoid a separate request for a small asset, but it cannot be cached independently. Compare both approaches for your page; large images are usually better served as ordinary files.
How it works
Add an image
Drop a PNG, JPEG, WebP or GIF, or use the file picker. The format is read from the signature; SVG is refused.
Copy the string or a snippet
The data URI, the CSS declaration and the HTML tag are separate copy targets. Download writes the same URI to a .txt file.
Or go the other way
Paste a data URI or raw Base64, or load a .txt, .base64 or .b64 file. The decoder identifies the format and offers a download with the matching extension.
Common questions
Why is SVG rejected?
An SVG file is a document that can contain script, external references and event handlers. When an SVG data URI is used as an image source, some browsers and embedding contexts will execute that content. The risk is not worth the convenience, so both directions refuse SVG and say why.
Does the tool upload my image anywhere?
No. The file is read locally with the File API, and the preview is a blob URL in the same tab. There is no server-side step, so the tool also works with the network disconnected once the page has loaded.
Why is the data URI larger than the original file?
Base64 represents 6 bits per character, so three bytes become four characters. That is 4/3, or about 33 percent growth, plus a short header. A 300 KB PNG becomes roughly 400 KB of text.
What is the difference between the data URI and the snippets?
Nothing structural. The CSS snippet wraps the same string in background-image: url(...), and the HTML snippet wraps it in an img tag with an empty alt attribute. The URI itself is identical in all three.
Why did my pasted Base64 open as a different format?
Because the format comes from the file signature, not from the media type in the data URI header. That is deliberate: renamed files and copy-paste errors are common, and the bytes are the only reliable evidence of what the image actually is.
Related tools
Base64 converter
Two directions, converted as you type. Invalid characters, impossible lengths and bytes that are not valid UTF-8 are reported rather than turned into plausible-looking rubbish.
Image scramble
A visual lock, not encryption: the pixels move, the values stay. The shuffle is keyed with PBKDF2 and the salt travels inside the PNG.
JSON formatter
Paste JSON to indent it, compress it, sort its keys or find out why it will not parse. The output is built with JSON.parse and JSON.stringify, so it matches what a JavaScript runtime sees.