Bild-zu-Base64-Konverter

So wird es benutzt 3 Schritte
  1. Wählen Sie unter Bilddatei auswählen ein Bild.
  2. Drücken Sie In Base64 kodieren.
  3. Drücken Sie Data-URI kopieren und fügen Sie es in Ihr HTML oder CSS ein.
Base64-Data-URI-Zeichenkette

So funktioniert dieses Werkzeug

Die Datei wird gelesen und als Data-URL zurückgegeben — jene Zeichenkette, die mit data: beginnt, den Dateityp nennt und danach das ganze Bild base64-kodiert mitführt. Dieses Präfix gehört zum Ergebnis und macht es erst brauchbar: In ein Stylesheet oder ein img-Tag eingefügt funktioniert es unverändert, weil dem Browser vor Beginn der Daten gesagt wird, was er vor sich hat.

Diese Kodierung macht das Bild rund ein Drittel größer als die Datei, aus der es stammt — das ist der Handel. Dafür braucht das Bild keine eigene Anfrage: Es reist im HTML, CSS oder JSON mit, das darauf verweist, und kann weder zu spät kommen noch fehlen.

Wann das Einbetten die Größe wert ist

  • Klein und unveränderlich ist der Fall dafür: ein Symbol, ein Aufzählungszeichen, ein Ein-Pixel-Verlauf. Unterhalb weniger Kilobyte wiegt die gesparte Anfrage die zusätzlichen Bytes meist auf.
  • Große Bilder sind eingebettet schlechter dran: Ein in ein Stylesheet eingebettetes Foto macht dieses renderblockierend und getrennt nicht mehr cachebar — die Seite wartet also auf ein Bild, das sie nebenher hätte laden können.
  • Ein eingebettetes Bild lässt sich nicht eigenständig cachen: Es wird mit seiner Trägerdatei jedes Mal neu geladen, wenn diese sich ändert, während ein separates Bild im Browsercache geblieben wäre.
  • E-Mail ist der andere übliche Einsatz: Ein eingebettetes Bild kann nicht als externe Anfrage blockiert werden, allerdings ignorieren mehrere Clients Data-URLs ganz — testen Sie es, bevor Sie sich darauf verlassen.

What you get back is a data URL

Not raw base64 — a complete data URL, beginning with data:, naming the file's type, and carrying the encoded image after it.

That prefix is part of what makes the output usable. Pasted into a stylesheet or an <img> tag it works as it stands, because the browser is told what it is looking at before the data begins. Strip it only if something is specifically asking for the base64 alone.

The [msm_tool slug="image-to-base64"] reads the file in your browser, so nothing is uploaded.

The size cost is about a third

Base64 turns every three bytes into four characters, so expect the encoded version to be roughly 33% larger than the file it came from. That is the trade being made, and whether it is worth it depends entirely on the size of the image.

In exchange, the image needs no separate request. It travels inside the HTML, CSS or JSON that references it, and it cannot arrive late, arrive out of order, or go missing.

Where embedding wins

  • Small, unchanging assets. An icon, a bullet, a one-pixel gradient, a spinner. Below a few kilobytes the saved request usually outweighs the extra bytes.
  • Assets that must not fail. A logo in an error page that renders when the rest of the site is down.
  • Single-file deliverables. An HTML email, a self-contained report, a document someone will save and open offline.

Where it loses, and badly

Large images. A photograph inlined into a stylesheet makes that stylesheet render-blocking — the page cannot paint until the whole thing arrives, including an image the browser would otherwise have loaded in parallel. A 200KB photograph becomes 270KB of CSS that everything waits for.

Anything cacheable. An embedded image cannot be cached on its own. It is re-downloaded with its host file every time that file changes, where a separate image would have stayed in the browser cache across deployments. Inline a logo into your main stylesheet and every CSS change re-sends the logo to everyone.

Anything reused. The same icon embedded in five places is five copies. Referenced as a file, it is one request and then cache.

Email is the awkward case

Inlined images cannot be blocked as remote content, which is genuinely useful — most clients block remote images by default and your carefully designed email arrives as boxes.

But several major clients, Gmail among them historically, refuse data URLs in HTML email outright. So the technique solves one problem and can create another. Test in the clients your audience actually uses before committing to it; for email, a hosted image with good alt text is often still the safer choice.

SVG is usually better inlined as itself

If the image is an SVG, embedding the markup directly is almost always better than base64-encoding it. It is smaller than the encoded version, it can be styled with CSS, and it compresses well because it is text.

Base64 an SVG only when it must sit in a CSS url() and you cannot use the markup directly — and even then, URL-encoding the SVG rather than base64-encoding it produces a smaller result.

A rough rule

Under about 4KB, embedding is usually worth it. Between 4KB and 10KB, it depends on how often the host file changes. Over 10KB, use a file.

Those numbers are not precise and they do not need to be — the cases at either end are obvious, and the middle rarely matters much either way.

Häufig gestellte Fragen

Speziell zum Bild-zu-Base64-Konverter. Allgemeinere Fragen zu dieser Kategorie werden auf der Kategorieseite beantwortet.

Weil dieses Präfix sie brauchbar macht. Es nennt dem Browser den Typ, bevor die Daten beginnen. Entfernen Sie es nur, wenn ausdrücklich rohes base64 verlangt wird.
Base64 macht aus je drei Bytes vier Zeichen, rechnen Sie also mit gut einem Drittel mehr. Dieses Wachstum ist der Preis des Einbettens.
Kleine, unveränderliche — Symbole und dergleichen. Fotos sind als separate Dateien besser aufgehoben, die der Browser cachen und parallel laden kann.
Manchmal. Eingebettete Bilder lassen sich nicht als externe Inhalte blockieren, aber mehrere E-Mail-Clients verweigern Data-URLs rundweg. Testen Sie in den Clients, die Ihnen wichtig sind.
Nein. Es wird in Ihrem Browser gelesen, hier etwas Vertrauliches zu kodieren sendet also nichts irgendwohin.

Abonniere Benachrichtigungen zu neuen Tools, Funktionen und Produktivitätstipps.