Skip to content
Images and files

Image to Base64

Turn an image, audio file or font into a Base64 data URI, copy it as HTML, CSS, JSX, Markdown or JavaScript, and see what it costs in size.

Last checked

Files never leave your device. Everything runs in this tab.

Shrink images first
  • Data URI, plain base64, <img>, JSX, CSS, Markdown, JavaScript and @font-face forms
  • SVG as a shorter URL-encoded data URI for CSS backgrounds
  • The real size cost: file, text and the +33% overhead
  • Optional shrink to WebP or JPEG before encoding
  • Works for images, audio, video and fonts
  • Several files at once, copied one at a time

How to use it

  1. Drop one or more files. Any type works: images, audio, video, fonts.
  2. Pick the form you need under each file: data URI, plain Base64, HTML, CSS, JavaScript.
  3. Read the size note. Turn on Shrink images first to cut the text before you paste it.

What it checks and why

A data URI puts a file inside the page as text: data:image/png;base64, followed by the file in Base64. The browser needs no extra request, which is why playable ads, HTML emails and single-file pages use it.

Base64 turns every 3 bytes into 4 characters, so the text is about a third larger than the file. A 30 KB image becomes 40 KB of text. The tool shows both numbers, so you can see the real cost before you paste.

Inline small things only. Large data URIs cannot be cached separately, they slow down the first render and they count toward the size limit of a playable ad. The note under each file says when one is getting too big, and the shrink option re-encodes an image first.

Specs and sources

Limits

  • Files up to 25 MB are read, and a result over a few megabytes is slow to copy and paste.
  • The URL-encoded form is offered for SVG only. Binary files (PNG, JPEG, fonts, audio) always need Base64.
  • The shrink option re-encodes PNG, JPEG and WebP. SVG and GIF are left as they are.

Questions

What is a Base64 data URI?
A way to write a file as text inside a page, in the form data:image/png;base64,iVBORw0... The browser reads the file from the text and makes no request for it.
Why is the Base64 text bigger than the file?
Base64 uses 4 characters for every 3 bytes, so the text is about 33 percent larger. Gzip on the server wins part of that back for text, but not for images that are already compressed.
When should I inline an image as Base64?
For a few kilobytes at most on a normal page, such as a small icon. In a playable ad or an HTML email, where everything must live in one file, it is the normal way, and the shrink option helps keep the file small.
Should an SVG be Base64 or URL-encoded in CSS?
URL-encoded. SVG is already text, so it only needs a few characters escaped (<, >, #, % and quotes) instead of a full Base64 pass, so it skips the one-third Base64 overhead and stays readable. Pick URL-encoded SVG or CSS (URL-encoded) under the file.
Does the file get uploaded?
No. It is read in your browser and the text is made there. Nothing is sent anywhere.