FormatterHQ

Image to Base64

Turn any image into Base64 — as a data URI, raw Base64, a ready-made <img> tag, CSS background-image or Markdown — with a live preview.

Input TEXT
Output TEXT
Ready.

How to use the Image to Base64

  1. Drop a PNG, JPG, GIF, WebP, SVG or other image onto the upload area, or click it to choose a file from your device.
  2. Pick the Output format: Data URI, Raw Base64, HTML <img> tag, CSS background-image or Markdown image.
  3. Click Convert if the result does not appear automatically.
  4. Copy the Base64 output or download it as a text file.

Image to Base64 and data URIs

Converting an image to Base64 lets you embed it directly in HTML, CSS, Markdown, JSON or an email template instead of linking to a separate file. The result is usually used as a data URI — data:image/png;base64,… — which browsers treat exactly like an image URL. This tool reads your image locally, detects its type and gives you the Base64 in the format you need, with a preview to confirm it worked.

Output formats

For a 1×1 pixel PNG named dot.png:

OutputResult
Data URIdata:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
HTML <img> tag<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==" alt="dot.png">
CSS background-imagebackground-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==");
Markdown image![dot.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==)

Raw Base64 gives just the encoded data without the data: prefix, for APIs that take the MIME type in a separate field.

When embedding images makes sense

  • Small icons and UI sprites (a few kilobytes) in CSS, saving an HTTP request each.
  • Single-file documents: HTML reports, offline pages or notebooks that must work without external files.
  • APIs that accept images as JSON strings, such as many image-processing and AI services.
  • Placeholders like tiny blurred previews shown while the full image loads.

When it does not

  • Base64 is about 33% larger than the original file.
  • An embedded image cannot be cached separately; it is downloaded again with every page or stylesheet that contains it.
  • Large data URIs make HTML and CSS slower to parse. As a rule of thumb, keep embedded images under roughly 5–10 KB and serve larger ones as files.
  • Email support is mixed: several popular email clients do not display data URI images, so linked or attached (CID) images are more reliable for newsletters.

Before you paste the output

  • Fix the alt text. The HTML <img> output uses the file name as its alt value, as in alt="dot.png". Replace it with a short description of the picture, or with alt="" if the image is purely decorative, so screen readers do not read out a file name.
  • Consider plain text for SVG icons. SVG is already text, so in CSS you can also embed it URL-encoded as data:image/svg+xml,%3Csvg…. That form is often shorter than Base64 and compresses better with gzip, while Base64 is simpler because you never have to worry about which characters need encoding.
  • Match the MIME type. The data URI prefix comes from the detected file type. If you only copy the raw Base64 into an API, send the same type (for example image/webp) in the field the API provides, or the receiving service may reject the image.

Doing it in JavaScript

FileReader.readAsDataURL(file) produces the same data URI as this tool, keeping the original bytes. canvas.toDataURL('image/png') is different: it re-encodes whatever is drawn on the canvas, which changes the file size and drops metadata — useful for resizing, but not an exact copy.

Tips

Optimise the image before converting it — resize it to the displayed size with the Image Resizer and choose an efficient format. For vector graphics, SVG to Base64 also accepts pasted SVG code. To turn a Base64 string back into a picture, use Base64 to Image.

Your image is processed entirely in your browser and never uploaded.

Frequently asked questions

How do I use a Base64 image in HTML?
Choose the HTML <img> tag output and paste it into your page, or put the data URI in the src attribute of an existing img element.
Does converting to Base64 make the image bigger?
Yes, by about 33%. Base64 needs four characters for every three bytes of the original file.
Which image formats are supported?
Any image your browser recognises as an image file, including PNG, JPEG, GIF, WebP, BMP, ICO and SVG. The MIME type in the data URI is detected automatically.
Is my image uploaded to a server?
No. The file is read and encoded locally in your browser.
Is there a size limit?
There is no fixed limit, but very large images produce very long strings that are slow to copy and paste. Embedding is best for small images.

Last updated September 26, 2026

Guides

Related tools

Base64 to Image Preview and download images from Base64 strings or data URIs. Detects PNG, JPEG, GIF, WebP, BMP, ICO and SVG. Image to ASCII Art Converter Turn any photo or logo into ASCII art. Choose the width and character set, preview it in colour and copy the text. Image to Text (OCR) Extract text from images, screenshots and scanned PDFs with OCR in 28 languages. Edit, copy or download it, or make a searchable PDF. No upload. Flip Image (Mirror) Flip an image horizontally or vertically — mirror selfies, reverse text in photos or turn images upside-down — in your browser. Image Compressor Compress JPG, PNG and WEBP images in your browser with a quality slider, before/after comparison, resizing and batch ZIP download. Image Cropper Crop images online with a draggable selection, aspect ratio presets (1:1, 4:3, 16:9…) and exact pixel values. Private and free. JPG to Base64 Convert a JPG/JPEG photo to a Base64 string or data URI, with preview and size information. JSON to Base64 Convert JSON to a Base64 string online. UTF-8 safe, validates the JSON first; paste text or upload a .json file. MP3 to Base64 Convert MP3 audio files to Base64 or a data URI you can play directly in an HTML audio element. Octal to Base64 Convert octal byte values (000–377) to a Base64 string. Separate the values with spaces, commas, semicolons or line breaks. PNG to Base64 Convert a PNG image to a Base64 string or data URI with a live preview. SVG to Base64 Convert SVG markup or an .svg file to a Base64 data URI for CSS backgrounds, img tags and JSON.