TextSorter

Drag & Drop an image here

or click to browse files (PNG, JPG, SVG, WebP, GIF)

Preview of the uploaded image

Base64 Output

How to Convert an Image to Base64 Online

A Base64 data URI takes an image that would normally live in its own file and folds it straight into a string of text, small enough to sit inside an HTML attribute, a CSS declaration, or a JSON field. Instead of your browser making a separate trip to the server for logo.png, the picture rides along inside the very document that needs it. This converter builds that string entirely on your own device, so you can go from image file to embeddable code in the time it takes to drag and drop.

The workflow is deliberately short. Drop a PNG, JPG, SVG, WebP, or GIF file into the dropzone above, or click it to open a normal file picker. The moment the browser finishes reading the file, a preview appears and the Base64 output box fills in automatically, no separate "convert" button to click and no page reload to wait through.

  1. Choose your image. Drag a file from your desktop or file manager into the dropzone, or click the dropzone to browse for one. Anything your browser can display as an image, it can encode.
  2. Let it decode automatically. The tool reads the raw bytes of your file using the browser's own FileReader API and encodes them into a Base64 string the instant the file loads.
  3. Pick an output format. Use the Output Format dropdown to switch between a raw data URI string, a ready-made CSS background-image declaration, or a complete HTML img tag.
  4. Copy or download the result. Click Copy Code to grab the exact text on your clipboard, or Download Text if the string is long and you'd rather save it as a file to paste from later.

Because the whole process runs as JavaScript inside your own browser tab, there is no upload step, no waiting on a server queue, and no limit imposed by anyone other than your own computer's memory.

Understanding Data URI Syntax

Every Base64 image string this tool produces follows the same pattern defined by the data URI scheme: data:[mime-type];base64,[encoded-data]. The data: prefix tells the browser this is not a normal URL pointing somewhere else, it is the content itself, arriving inline. The mime type immediately after, something like image/png, image/jpeg, image/svg+xml, or image/webp, tells the browser exactly how to interpret the bytes that follow so it can render a PNG as a PNG and an SVG as an SVG rather than guessing from a file extension that no longer exists.

The ;base64 flag marks the encoding used for the payload, and everything after the comma is the actual image data, translated from raw binary into the 64-character alphabet of uppercase letters, lowercase letters, digits, plus, and slash. A tiny 16 by 16 favicon might produce a string only a few hundred characters long, while a detailed photograph can stretch into hundreds of thousands of characters, all sitting on a single unbroken line.

ContextExample Syntax
CSS backgroundbackground-image: url(data:image/png;base64,iVBOR...);
HTML image tag<img src="data:image/jpeg;base64,/9j/4AA...">
Inline SVG data URIdata:image/svg+xml;base64,PHN2ZyB4b...
CSS custom property--icon-close: url(data:image/svg+xml;base64,...);

This tool handles the mime-type detection and the encoding automatically based on the file you drop in, so you never have to write that prefix by hand, but recognizing the pattern helps when you are debugging why a string pasted into the wrong context refuses to render.

The 33% Size Overhead: Why Base64 Strings Are Bigger Than the Original File

Base64 encoding works by grouping the original binary data into chunks of 3 bytes and mapping each chunk onto 4 printable text characters. That 3-to-4 ratio is fixed by the math of the encoding, not by the image format or compression settings, and it means every Base64 string is roughly 33% larger than the file it came from, before any additional gzip or Brotli compression the server might apply on top.

In practice that means a 60 KB icon sprite becomes close to 80 KB once encoded, and a 300 KB photograph balloons past 400 KB. For a single small icon that difference is invisible to a user. Repeated across a page full of inlined thumbnails, or baked into a CSS file that ships to every visitor on every page load, that overhead adds up into a genuinely heavier document than serving the same images as separate files.

It is worth remembering that this expansion happens on top of the file, not instead of it. Converting a JPEG to Base64 does not compress the JPEG any further, it only changes how the same compressed bytes are represented as text, so any image optimization, such as resizing a photo or running it through a format like WebP, should happen before you encode it, never after.

When Inlining an Image Helps (and When It Hurts) Performance

Every image referenced by <img src="..."> or a CSS url(...) normally triggers its own HTTP request. On older HTTP/1.1 connections, browsers could only open a handful of simultaneous connections per domain, so a page with dozens of small icons genuinely suffered from that request overhead, and folding those icons into Base64 strings removed the extra round trips entirely. That is the original case for inlining, and it still holds for small, decorative graphics that appear once and rarely change.

Modern HTTP/2 and HTTP/3 connections multiplex many requests over a single connection, which weakens the original argument considerably. Fetching ten small external files over HTTP/2 is no longer nearly as expensive as it was a decade ago, while the 33% size penalty from Base64 encoding has not gone anywhere. That shifts the balance back toward linked files for most everyday images, reserving inlining for cases where avoiding even one extra request still matters, such as above-the-fold hero graphics that must appear the instant the HTML parses, or single-file tools that cannot rely on a second network request at all.

A useful rule of thumb: inline the very small stuff, icons, spinners, tiny logos, generally under 5 to 10 KB, and link everything else. A large inlined image also delays the browser from finishing the parse of the surrounding HTML or CSS document, since it has to read through the entire encoded string before moving on, which can push back the point where the rest of the page becomes visible.

Using Base64 Images in CSS

The most common home for a Base64 image is a CSS background-image declaration, which is exactly what the CSS output format in this tool produces. Selecting that format wraps your encoded string in background-image: url('data:image/png;base64,...');, ready to paste directly into a stylesheet, a <style> block, or an inline style attribute.

This pattern shows up constantly for small, repeated visual details: a subtle noise texture behind a card, a custom bullet icon replacing the default list marker, a checkbox or radio button's checked state, or a decorative SVG divider between sections. Because the image travels with the CSS itself, there is nothing extra for the browser to fetch once the stylesheet has loaded, which matters for components that appear the instant the page renders, before any lazy-loaded assets have had a chance to arrive.

The tradeoff is that CSS containing large Base64 strings becomes noticeably harder to read and maintain, and that inflated stylesheet has to be downloaded and parsed in full before the browser can apply any of the styles that follow it. Keeping Base64 images in CSS limited to genuinely small assets, and reaching for a normal url('/images/photo.jpg') reference for anything bigger, keeps both the stylesheet and the page itself fast.

Base64 Images in HTML and the Reality of Email Templates

Selecting the HTML output format wraps your encoded string in a ready-to-use <img src="data:image/png;base64,..." /> tag, which works exactly like a normal image tag anywhere a browser renders HTML, including single-page reports, exported documents, and offline tools that need to work as one self-contained file with no external assets at all.

Email is the one place where this pattern deserves real caution. Gmail and Apple Mail generally render Base64 embedded images without complaint, but desktop versions of Outlook use Microsoft Word's rendering engine rather than a modern browser engine, and that engine frequently strips or simply refuses to display data URI images. A marketing email built around inlined logos might look perfect in a personal Gmail inbox and show a broken image icon to a large share of corporate Outlook users. For anything sent as a mass email, a normally hosted image with a well written alt attribute remains the dependable default, and Base64 is best reserved for HTML you fully control the rendering of, such as an in-app notification, a PDF export, or a printable receipt.

Outside of email, this same self-contained quality is genuinely useful: a single HTML file that includes its own logo and icons as Base64 strings can be emailed as an attachment, opened straight from a local disk, or archived indefinitely, all without a single broken image link, because there is no external file for a future move or rename to break.

SVG and Base64: When Encoding Actually Helps

SVG occupies an unusual spot in this whole conversation because an SVG file is already plain text, not binary data. That means it can be embedded in a CSS url() using ordinary URL encoding instead of Base64, and a URL-encoded SVG is frequently smaller than the same file run through Base64, since URL encoding only escapes a handful of special characters rather than re-expressing every byte in a 4-character alphabet.

Base64 still earns its place with SVG in a few specific situations. It is the simplest option whenever the surrounding context cannot tolerate the quotes, hashes, and angle brackets that raw or URL-encoded SVG markup contains, such as inside a single JSON string, a database column, or a CSS custom property value where escaping gets awkward. It also travels well as an <img src="data:image/svg+xml;base64,...">' attribute, and this tool produces exactly that format automatically when you drop in an SVG file and choose the HTML output.

What Base64 cannot do for SVG is preserve its biggest advantage: live styling. An SVG pasted directly into your HTML as inline <svg> markup can have its fill color changed with CSS currentColor, respond to :hover, and be manipulated with JavaScript, none of which is possible once it is flattened into an opaque Base64 string. If you need a themeable icon, keep the SVG markup inline. If you need a portable, opaque image reference, Base64 encoding it is the right call, and this tool handles that conversion in one drop.

Browser Caching Tradeoffs

A normal image file referenced by URL gets its own entry in the browser's HTTP cache, governed by whatever Cache-Control headers the server sends. Visit ten pages that all reference the same /logo.png, and the browser downloads that file exactly once, then reuses the cached copy on every subsequent page for as long as the cache header allows, sometimes for months.

A Base64 image gets no such privilege. Because it lives inside the parent HTML or CSS document rather than as its own resource, it is downloaded, parsed, and decoded fresh every single time that parent document loads, even across pages that reuse the exact same picture. There is no separate cache entry for the browser to reuse, since as far as the caching layer is concerned there is no separate resource at all, just more bytes inside a document it was already going to fetch.

This is the single biggest argument against inlining anything that appears more than once across a site. A shared logo, a repeated icon set, or a background pattern used sitewide is far better served as a linked file with a long cache lifetime, downloaded once and reused everywhere, than as a Base64 string duplicated into every page and stylesheet that needs it. Reserve inlining for images genuinely unique to a single document, where there is nothing to share a cache entry with in the first place.

Common Ways People Use This Base64 Image Converter

Developers building single-page apps or internal dashboards use Base64 for tiny placeholder graphics and loading-state icons that need to render before the main JavaScript bundle finishes downloading, since an inline data URI paints instantly with the very first byte of HTML rather than waiting on a second request.

Anyone generating offline reports, exported PDFs, or single-file HTML deliverables reaches for Base64 to keep a document truly self-contained, with its logo, charts, or diagrams baked directly into the file so nothing breaks when that file is emailed, archived, or opened years later on a machine with no access to the original image hosting.

Designers and front-end developers use the CSS output format constantly for small UI decorations, custom checkbox and radio button states, subtle background textures, and icon fonts replacements, where the asset is small enough that the 33% overhead barely registers but the saved request genuinely speeds up first paint.

And because the whole conversion happens locally, people who need to convert something sensitive, a scanned signed contract, a private ID photo, an unreleased product screenshot, use this tool specifically because it never asks anything to leave their own device.

Why This Converter Runs Entirely in Your Browser

Plenty of "convert image to Base64" tools quietly upload whatever you drop on them to a server, encode it there, and send the string back. That round trip is invisible if you are converting a public logo, but it is a real concern the moment the image is a signed document, a private photo, a screenshot of confidential data, or any pre-release design asset you would not want sitting on someone else's server, even briefly.

This converter never makes that trip. It reads your file using the browser's built in FileReader API, encodes the bytes with JavaScript running on your own device, and displays the result, all without a single network request carrying your image anywhere. Open your browser's network tab while using it and you will not find your file leaving the page. That also means there is no server-side size limit, no processing queue to wait behind, and no dependency on a third-party API staying online; the conversion is exactly as fast and as available as your own computer.

For teams handling client assets, internal branding still in development, or anything covered by a confidentiality agreement, a purely client-side tool removes the trust question entirely rather than asking you to read a privacy policy and hope. It is the same reasoning that leads developers to run a formatter or linter locally instead of pasting proprietary source code into a random web form.

Frequently Asked Questions

What is a Base64 data URI and how does a browser read it?
A data URI packs a file directly into a string using the format "data:[mime-type];base64,[encoded-data]", so instead of pointing at a separate file the browser decodes the string on the spot. The mime type tells the browser what it is looking at, such as image/png or image/svg+xml, and everything after the comma is the actual image content translated into Base64 text.
Why is the Base64 string so much larger than my original image file?
Base64 encoding turns every 3 bytes of binary image data into 4 text characters, which inflates the payload by roughly 33% before any compression is applied. A 90 KB PNG will typically produce a Base64 string in the neighborhood of 120 KB, so the convenience of inlining always comes with a real size cost.
When should I inline an image with Base64 instead of linking to a file?
Base64 is a good fit for small, frequently reused graphics such as icons, logos, or tiny UI decorations where saving an extra HTTP request matters more than the 33% size penalty. For large photographs, hero banners, or anything above roughly 5 to 10 KB, a normal linked file is almost always faster because the browser can cache and reuse it independently.
Can I use Base64 encoded images inside HTML emails?
It depends heavily on the email client. Gmail and Apple Mail generally render inline Base64 images fine, but desktop Outlook uses a Word based rendering engine that frequently strips or ignores data URI images entirely, so a hosted image with a proper alt attribute is still the safer default for a mass email campaign.
Is Base64 a good choice for SVG files specifically?
Sometimes, but not always. Because SVG is already plain text markup, a URL encoded SVG in CSS is often smaller than the same file run through Base64, and pasting the raw <svg> markup directly into your HTML lets you style it with currentColor and CSS, which a Base64 string cannot do. Base64 is mainly useful for SVG when you need it inside a single opaque data attribute or a CSS custom property.
Does browser caching still work once an image is converted to Base64?
No, not independently. A linked image file gets its own cache entry that the browser can reuse across every page that references it, while a Base64 string is baked directly into the parent HTML or CSS document, so it gets re-downloaded and re-parsed every single time that document loads, even if the underlying picture never changes.
Is there a file size limit on this converter?
There is no hard limit enforced by the tool itself since everything runs in your browser's own memory, but very large source images, roughly above 2 MB, can produce a Base64 string long enough to noticeably slow down the tab or make the output box sluggish to scroll. For anything that big, a linked file is the better choice anyway.
Is my image private when I use this converter?
Yes. The entire conversion happens locally using the browser's built in FileReader API, so the image you drop into the tool is never uploaded, transmitted, or stored on any server. That makes it safe to convert scanned documents, private screenshots, or unreleased design assets without any of that content leaving your device.
What is the difference between the Raw, CSS, and HTML output formats?
The Raw format gives you the bare data URI string by itself, ready to paste wherever your project expects a URL. The CSS format wraps that same string in a background-image: url(...) declaration, and the HTML format wraps it in a complete <img src="..."> tag, so you can copy exactly the syntax your stylesheet or markup needs without editing it by hand.
When should I avoid Base64 encoding altogether?
Skip it for large photographs, product images, or anything a user might see repeated across several pages, since a linked file lets the browser cache and reuse that download instead of re-fetching an inflated text blob every time. It is also worth avoiding on pages where every kilobyte of initial HTML matters for perceived load speed, because a large inline string delays the browser from finishing the parse of the surrounding document.

Related developer tools

🔒 100% Client-Side Privacy

Every image is decoded and encoded <strong>entirely in your browser</strong>. Nothing is uploaded to any server. Your image stays on your device.