Skip to content
Back

Image to Base64 Converter

Turn a PNG, JPG, WebP, GIF or SVG into a Base64 data URI, with ready-made HTML and CSS snippets.

Files are processed entirely in your browser — they're never uploaded to a server.

Put a small image straight into your HTML or CSS

A data URI lets an image live inside the code that uses it. Instead of src="arrow.svg" you write the whole file into the attribute as text, and the browser has nothing extra to fetch.

Drop a PNG, JPEG, WebP, GIF or SVG here (AVIF and ICO work too) and you get the Base64 text, the full data URI, and three snippets ready to paste: an <img> tag with the width and height filled in, a CSS background-image line and a Markdown image. The image type is read from the first bytes of the file, not from its name, so a JPEG saved as logo.png still gets the right image/jpeg label.

The file is read by your browser and never uploaded. For plain text rather than images, use the Base64 Encoder.

How to convert an image to Base64

  1. Click the upload area or drag one image onto it. Files up to 10 MB are accepted.
  2. Check the details: type, size in pixels, file size and how long the Base64 version is.
  3. For an SVG, choose URL-encoded or Base64. The shorter one is picked for you, and both lengths are shown on the buttons.
  4. Click Copy next to the output you need. The Base64 text and the data URI can also be saved as a .txt file.
  5. Paste the snippet into your page, then replace alt="" in the <img> tag with a short description unless the image is purely decorative.

Which output to copy

  • Base64 only: just the encoded characters, for a JSON field, an API that asks for Base64, or a template that adds its own prefix.
  • Data URI: the same text with data:image/png;base64, (or the right type) in front. This is what goes into src, href or url().
  • HTML <img> tag: the data URI in src, plus width and height taken from the image so the page doesn’t jump while it renders.
  • CSS background-image: one declaration with the URI in double quotes. Add your own background-size and background-repeat.
  • Markdown image: always the Base64 version, because Markdown links break on spaces. Many Markdown hosts, GitHub among them, don’t display data URI images at all, so test it where it will be shown.
  • Outputs longer than 200,000 characters show only their start in the box, so the page stays usable. Copy and Download still use the full text.

When inlining helps, and when it hurts

A data URI saves one request but gives up separate caching. That trade only pays off for small images.

  • Good fit: small icons and arrows under a few KB, a loading spinner that must show before anything else arrives, or a logo in a single-file HTML report you email as an attachment.
  • Also good: APIs and config files that expect an image as a string, and throwaway demos where hosting a separate file is more trouble than it’s worth.
  • Poor fit: photos and anything over roughly 10 KB. An image file is downloaded once and cached; a data URI is downloaded again inside every page that contains it, and a large one in a stylesheet delays the first paint because CSS blocks rendering.
  • Images used on many pages: a header logo inlined into 50 pages is fetched 50 times. As a normal file it’s fetched once. This tool warns you above 100 KB, but the sweet spot is far smaller.

Why the text is bigger than the file

Three bytes become four characters

Base64 writes every 3 bytes of the file as 4 characters from a 64-character alphabet, and pads the end with = so the length is always a multiple of 4. The exact length is 4 × ⌈bytes ÷ 3⌉: a 1,024-byte icon becomes 1,368 characters, and a 100 KB photo becomes about 133 KB of text.

Gzip or Brotli on your server wins much of that extra third back when the page is sent. What they can’t fix is caching, which is the bigger cost for anything but tiny images.

SVGs don’t need Base64

SVG is already text, so it can go into a data URI with only a few characters escaped: < becomes %3C, # becomes %23, double-quoted attributes switch to single quotes, and so on. For a typical icon that comes out shorter than Base64, and it stays readable enough to tweak a colour by hand.

The URL-encoded version keeps spaces as plain spaces. Browsers accept that in src and inside url("…"), but the W3C HTML validator flags it, and it breaks a srcset, which uses spaces to separate entries. Use the Base64 version in those cases.

Image to Base64 Converter: common questions

Can I use a Base64 image in an email?

Not reliably. Gmail and many versions of Outlook don’t show data URI images, while Apple Mail does, so half your readers could see a broken image. For an email signature logo, link to an image hosted on your website or attach it as an inline (CID) image instead.

Why does the tool say my .png is actually a JPEG?

Because the file starts with the bytes of a JPEG. Renaming a file doesn’t convert it, and some apps save JPEGs with whatever extension you type. The data URI uses the real type, image/jpeg, so browsers display it correctly. If you need a true PNG, convert the file in an image editor first.

Does a data URI load faster than a normal image?

For a tiny image, it can, because the browser skips one request. For anything larger it is usually slower: the page or stylesheet that carries it gets heavier, it can’t be cached separately, and over HTTP/2 an extra request is cheap anyway.

Why are some files refused?

The tool only takes images that browsers can display from a data URI. HEIC photos from an iPhone need converting first with the HEIC to JPG Converter, BMP and TIFF files should be saved as PNG, and anything over 10 MB is refused because a data URI that size would make any page crawl. To shrink a photo before inlining it, try the Image Compressor.