πŸ”

Image to Base64

βœ“ Free & no signup πŸ”’ Runs 100% in your browser Updated 2026-11-25 Images Editing Tools
πŸ”

Drop an image here
or click to choose a file (PNG, JPG, WebP, GIF, SVG)

Embedding an image directly into HTML, CSS, or JSON means encoding it as Base64. The result is a single text string that starts with data:image/png;base64, followed by a long wall of characters representing every byte of the file. This tool produces that string for you: drop in an image, get the complete data URI, and copy it straight into your code, including a ready-made CSS background-image snippet.

Everything happens locally in your browser. The file is read with the FileReader API, encoded in memory, and shown back to you. Nothing touches a server, no account is needed, and the same flow works on mobile. Sensitive assets, internal design files, and client work all stay on your machine.

Base64 encoding is powerful but easy to misuse. The output is roughly 33 percent larger than the original binary file, and data URIs are not cached the way normal image requests are. Used deliberately, for small icons and critical above-the-fold graphics, it is a genuine performance win. Used carelessly on large photos, it bloats documents and slows pages down. This page gives you the numbers to decide which side your image falls on.

What Base64 Encoding Actually Does

Base64 converts binary data into 64 safe ASCII characters: A through Z, a through z, 0 through 9, plus + and /. Every 3 bytes of input become 4 characters of output, which is exactly where the one-third size increase comes from. Mathematically: 3 bytes equal 24 bits, and 24 bits split into four 6-bit groups, each mapped to one of the 64 characters. If the input length is not divisible by 3, the encoder pads the output with one or two = signs.

A quick worked example: a 4,500-byte PNG icon encodes to 6,000 characters, because 4,500 divided by 3 is 1,500 groups and each group yields 4 characters. Add the data:image/png;base64, prefix of 23 characters and the final URI is about 6 KB of text. A 250 KB JPEG photo, by contrast, becomes roughly 333 KB of text, which is usually a sign you should be linking the file instead.

Encoding overhead at three sizes

Original fileBase64 outputOverheadVerdict
1.2 KB icon PNG1.6 KB~33%Good candidate
18 KB sprite/logo24 KB~33%Situational
240 KB photo JPEG320 KB~33%Link it instead

How to Convert an Image to Base64 (Step by Step)

  1. Drop your image onto the upload area or click to browse. PNG, JPEG, WebP, and GIF all work; the tool reads the file locally and reports its exact byte size.
  2. Wait for the encoding preview. You see the image rendered and the full data URI generated below it.
  3. Copy the raw data URI with one click if you are inserting it into HTML, such as an img src attribute.
  4. Use the CSS snippet button to copy a complete background-image: url(data:image/...); rule, ready to paste into a stylesheet or inline style.
  5. Paste into your project. The image now travels inside your code file, with no separate request ever made.

Key Features

  • Complete data URI output: the full data:image/TYPE;base64, prefix is included, so the string works immediately as an img src or CSS url() value.
  • Copy-as-CSS mode: one click produces a formatted background-image declaration instead of a bare string.
  • Byte-accurate reporting: the tool shows the original file size and the encoded string length so you can judge the overhead before committing.
  • Local processing: encoding happens in the browser via FileReader; private screenshots and client assets never leave the device.
  • Free and unlimited: no signup, no watermark, works on desktop and mobile browsers.

When a Data URI Is the Right Call

  • Tiny UI icons under about 2 KB, where the HTTP request overhead would rival the image itself.
  • Critical hero or logo graphics that must render on the very first paint, because a data URI arrives with the HTML instead of requiring a separate round trip.
  • Single-file deliverables: an HTML email template, an offline documentation page, or a self-contained demo where external files are inconvenient or forbidden.
  • Small decorative sprites reused across a stylesheet, sparing the server repeated icon requests.
  • JSON payloads for APIs that must carry an image inline, since JSON is text and binary needs encoding anyway.

When to Avoid It

Three concrete reasons to skip Base64 for anything large. First, the 33 percent overhead: a 300 KB photo becomes 400 KB of text on every page view. Second, no caching: a normal image file is downloaded once and served from the browser cache afterward, while a data URI embedded in a stylesheet or HTML page is re-downloaded every time that page or stylesheet changes, even if the image itself never did. Third, no lazy loading or responsive variants; the browser cannot defer or optimize what is baked into the document.

A common measurement makes the trade-off concrete. Suppose a page uses six 1 KB icons. Linked files cost six requests but about 6 KB total, cached on return visits. Inline data URIs cost zero requests but about 8 KB of extra HTML, re-transferred on every visit unless the whole document is cached. For icons, inline usually wins on first visit and roughly ties afterward. For photos, linked files win decisively in every scenario.

Using the Output in Real Code

In HTML, drop the URI directly into an image tag: the src attribute accepts the entire data URI as-is. In CSS, the copied snippet slots into any rule. In JavaScript, the string works as an img.src value or as the source for a canvas drawImage call. In JSON, the URI is a plain string value and survives serialization without escaping, because Base64 uses only characters that are safe inside JSON strings.

Watch the MIME type in the prefix. It must match the actual image: data:image/png;base64 for PNG, data:image/jpeg;base64 for JPEG. A mismatched prefix can prevent decoding in strict contexts, such as some canvas security checks and content-security-policy configurations that pin exact types.

Tips and Best Practices

  • Compress before encoding. Minify the PNG or set JPEG/WebP quality around 0.85 first; encoding a bloated source multiplies an already unnecessary size by 1.33.
  • Keep inlined images under roughly 2 to 5 KB. Beyond that, the overhead and lost caching outweigh the saved request.
  • Inline into CSS rather than HTML when the image is reused, so it is defined once and referenced everywhere in that stylesheet.
  • For HTML email, note that Gmail has a per-message size limit around 102 KB for the whole HTML; every Base64 image eats directly into that budget.
  • If your build pipeline supports it, prefer asset inlining at build time over pasting giant strings into source files, keeping your repository readable.

Base64 Encoding vs. Linking a File

FactorData URI (Base64)Linked image file
RequestsZeroOne per image (cached after first)
Transfer size+33% overhead every loadExact file size, cached afterward
First paintImmediate, ships with HTMLWaits for image request
Browser cachingNone, re-downloaded with documentFull HTTP caching
Best forIcons under ~2 KB, single-file pagesPhotos and anything reused across pages

Frequently Asked Questions

How do I convert an image to Base64?
Upload the image to this tool and it generates the full data:image/...;base64 URI instantly in your browser. You can copy the raw string or a ready-made CSS background-image snippet. The file is read locally with the browser's FileReader API and never uploaded to a server, so the process is private and works on mobile as well as desktop.
How much bigger is Base64 than the original image?
Base64 output is about 33 percent larger than the binary file. The encoding turns every 3 bytes into 4 characters, so a 4,500-byte icon becomes 6,000 characters, and a 240 KB photo becomes roughly 320 KB of text. There is no way around this overhead; it is a property of the encoding, which is why Base64 is best reserved for small images.
Is it good practice to embed images as Base64?
For small icons and critical above-the-fold graphics, yes: a data URI eliminates an HTTP request and renders on first paint. For photos or anything over a few kilobytes, no: the 33 percent overhead plus the loss of browser caching usually makes pages slower. A practical cutoff is around 2 to 5 KB per image.
Do Base64 data URI images get cached by the browser?
Not independently. A data URI is part of the HTML or CSS that contains it, so it is only cached when that whole document or stylesheet is cached. Change one character in the HTML and every embedded image re-downloads. A separately linked image file, by contrast, is cached by its own URL and reused across pages and visits.
What is the data:image/png;base64 prefix for?
It is the MIME type declaration of a data URI, telling the browser how to interpret the payload that follows. PNG uses data:image/png;base64, JPEG uses data:image/jpeg;base64, and so on. The prefix must match the actual encoded image, because a mismatched type can block decoding in strict contexts like canvas operations and certain content security policies.
Can I use a Base64 image in HTML email?
Yes, and many templates do, but watch the size budget. Gmail clips messages at about 102 KB of total HTML, and Base64 inflates every image by roughly a third. Keep embedded images tiny, a few kilobytes each, and test in the major clients, because some older or stricter mail providers strip data URIs entirely.

Related Tools