Convert an image to Base64

Get the Base64 text for an image, ready to paste into HTML, CSS, JSON or an email template. Pick the format and copy it with one tap.

FreeNo sign-upRuns on your device

Loading the tool…

How to use it

  1. Choose an image, or drop it onto the box.
  2. Pick Data URL, Base64 only, CSS or HTML img.
  3. Press Copy to clipboard, or save the text as a file.

What Base64 is for

Base64 writes binary data, like an image, as plain text. A data URL puts that text after a short header such as data:image/png;base64, so a browser can show the image without a separate file. Developers use it to embed small icons in CSS, put images inside HTML emails or single-file pages, and send images through JSON APIs that only accept text. It saves the browser a separate request for each tiny image, which can help when a page uses many small icons. Email clients vary in how they treat embedded images, so test a message before sending it widely.

The four output formats

Data URL is the complete value you can use as an image source. Base64 only gives just the encoded text with no header, which is what most APIs want. The file type in the header comes from the file itself, so a PNG stays image/png and an SVG stays image/svg+xml. CSS wraps the data URL in a background-image rule, and HTML img wraps it in an image tag you can paste into a page.

Keep embedded images small

Base64 text is about a third larger than the original file, and an embedded image can't be cached separately by the browser. It's a good fit for icons and small graphics of a few KB. For photos, a normal image file is almost always better. If you must embed a larger image, run it through Compress image or Convert to WebP first. The tool warns you when a file is over 1 MB.

The image is read on your device and nothing is uploaded, so it is safe to use with private files.

Questions

How do I use a Base64 image in HTML?

Choose HTML img and copy the tag, or use the Data URL as the src of an img element.

Why is the Base64 text bigger than my file?

Base64 uses 4 characters for every 3 bytes, so it is about 33% larger than the original.

Can I convert an SVG to Base64?

Yes. SVG files are supported and keep their image/svg+xml type in the data URL.

Is my image uploaded?

No. It is read and encoded in your browser.