Home/Image Tools/Image to Base64
🔐

Image to Base64

FREE

Encode an image as a Base64 data URL for HTML, CSS or JSON

Free · No sign-up required
Loading...

What Image to Base64 does

This tool reads an image file and produces its Base64 encoding — a text representation of the binary data — along with a ready-to-paste data URL, an HTML <img> tag and a CSS background-image rule. Embedding an image as text lets you include it directly inside an HTML page, a stylesheet, a JSON payload or an email without a separate file. The encoding is done in your browser with the FileReader API; the image is not uploaded.

What a data URL looks like

A data URL bundles the MIME type, the encoding and the data into one string:

PartExampleMeaning
Schemedata:Inline data rather than a network address
MIME typeimage/pngWhat the bytes are
Encoding flag;base64The payload is Base64 text
PayloadiVBORw0KGgoAAAANSUhEUg…The file's bytes, encoded

Put together: data:image/png;base64,iVBORw0KGgo…. Browsers accept it anywhere a URL is expected — src, href, CSS url() — and decode it on the spot.

When embedding is a good idea

  • Tiny icons and logos under about 2 KB, where a separate HTTP request costs more than the bytes.
  • Single-file deliverables — an HTML report, an email template or a standalone widget that must work with no external assets.
  • Critical above-the-fold images in a page's first render, avoiding a round trip.
  • APIs and JSON that need to carry a small image (an avatar, a QR code) inside a text payload.
  • Environments that block external URLs, such as some email clients and sandboxed previews.

When it is a bad idea

Base64 makes data about 33% larger (every 3 bytes become 4 characters), and embedded images cannot be cached separately from the page, so they are re-downloaded every time the page is. A 200 KB photo becomes 270 KB of text that bloats the HTML, delays parsing, and cannot be lazy-loaded. Rules of thumb:

  • Under 2 KB: embedding is usually a win.
  • 2–10 KB: judgement call; fine for a one-off, poor for a repeated asset.
  • Over 10 KB: serve as a file. Use a CDN, HTTP/2 and caching instead.

Modern HTTP/2 and HTTP/3 make many small requests cheap, which has narrowed the case for inlining; in 2026 it is mostly a tool for self-contained documents rather than a performance technique.

Using the output

ContextSnippet
HTML<img src="data:image/png;base64,…" alt="…">
CSSbackground-image: url("data:image/svg+xml;base64,…");
Markdown![alt](data:image/png;base64,…)
JSON{ "avatar": "data:image/jpeg;base64,…" }
Email HTMLSame as HTML; supported by most clients except some Outlook versions

For SVG, plain URL-encoding (data:image/svg+xml,%3Csvg…) is often smaller than Base64 because SVG is already text; Base64 is still the safe choice when the SVG contains characters that break attribute quoting.

Security note

Base64 is encoding, not encryption — anyone can decode it instantly. Do not use it to hide an image, and be aware that data URLs can carry any file type: treat a data URL from an untrusted source with the same caution as a file download. Browsers block navigation to top-level data: URLs for this reason, though they still work in <img> and CSS.

Frequently asked questions

Why is the Base64 string longer than the file size?

Base64 represents 3 bytes as 4 ASCII characters, so output is always about 4/3 of the input, plus a few characters of header.

Can I convert Base64 back to an image?

Yes — paste the data URL into a browser's address bar (for img-safe types) or use the Base64 decoder tool, which can save the decoded bytes as a file.

Which image formats work?

Any file can be encoded. The data URL's MIME type is taken from the file, so PNG, JPG, GIF, WebP, SVG and ICO all produce valid URLs that browsers display.

Does it work for large images?

Yes, but the output string becomes unwieldy — a 5 MB photo produces nearly 7 million characters. Copy it programmatically rather than by hand.

Is the image uploaded?

No. The file is read with the browser's FileReader API and never leaves your device.

Why does my email client show a broken image?

Some clients, notably certain Outlook versions and Gmail's web client for larger images, block or strip data URLs. Host the image and link to it for reliable email display.

More tools in this category

🗜
Image Compressor
Re-encode JPG, PNG or WebP at a chosen quality to cut file size
📐
Image Resizer
Resize to exact pixels or a percentage with locked aspect ratio
Image Cropper
Crop freely or to 1:1, 4:3, 3:2 and 16:9 presets
🔄
Image Converter
Convert any image to JPG, PNG or WebP
💧
Image Watermark
Add a single or tiled text watermark with custom opacity
🔍
EXIF Data Reader
See camera settings, date and GPS location hidden in a photo