# 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.

- Page: https://codethatmoves.com/tools/images/image-to-base64/
- Site: Code That Moves
- Category: Images and files
- Free, runs in the browser, nothing is uploaded (files you drop in stay on your device)
- Last checked: 2026-11-03

## What it does

- Paste a screenshot or copied image with Ctrl+V (Cmd+V on a Mac) to get its data URI straight away
- Converts images, audio, video and fonts to Base64 and data URIs
- Copies as a data URI, plain Base64, HTML tag, JSX, CSS background, Markdown image, JavaScript constant or @font-face
- SVG also gets a URL-encoded data URI (data:image/svg+xml,...), usually shorter than Base64 because it skips the one-third Base64 overhead, ready for a CSS background
- Shows the file size, the image dimensions, the text size and the Base64 overhead, with a plain note on whether it is too big to inline
- Optional shrink to WebP or JPEG before encoding
- Several files at once, nothing uploaded

## 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.

## Reference data

| Form | What it is |
| --- | --- |
| Data URI | data:<type>;base64,<data>, usable anywhere a URL is |
| Base64 only | The encoded text without the data: prefix |
| HTML tag | An img, audio or video tag with the data URI as its source |
| CSS background | background-image: url(data URI) |
| JavaScript | A const holding the data URI |
| @font-face | A font rule with the data URI as its source, for font files |

## Specs and sources

- [RFC 2397: The data URL scheme](https://datatracker.ietf.org/doc/html/rfc2397)
- [RFC 4648: Base64 encoding](https://datatracker.ietf.org/doc/html/rfc4648)
- [MDN: Data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs)

## 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.
