Skip to content
ToolZone

Image to Base64

Convert an image into a Base64-encoded data URI, letting you embed the image directly inside HTML, CSS, or JSON without a separate file.

Runs in your browser. Nothing you enter or upload leaves your device.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the Image to Base64

Image to Base64 converts a picture into a data URI: a text string that starts with data:image/...;base64, and contains the whole file encoded as Base64. You can paste it directly into an img src, a CSS background or a JSON field, with no separate image file needed.

How it works

The tool reads your file with the browser's FileReader.readAsDataURL, which produces data:, the file's MIME type (such as image/png), ;base64, and then the file's bytes encoded in Base64. The bytes are not changed or re-compressed; it is the exact original file written as text.

Base64 represents every 3 bytes as 4 characters from a 64-character alphabet (A-Z, a-z, 0-9, + and /), padding the end with =. That is why the encoded string is about 33% larger than the file. The output panel shows only the first 500 characters to keep the page fast, but the Copy button copies the entire string.

How to use

  1. 1

    Click the file button and choose an image.

  2. 2

    Check the preview to make sure it is the right image.

  3. 3

    Click Copy to copy the full data URI.

  4. 4

    Paste it into an img src attribute, a CSS url(), or wherever you need it.

Worked examples

Icon in CSS

A 1.2 KB PNG icon used as a button background.

Input
icon.png (about 1,200 bytes)
Result
data:image/png;base64,iVBORw0KGgo... (about 1,622 characters)

Every PNG's Base64 begins with iVBORw0KGgo, the encoded PNG signature. 1,200 bytes become 1,600 Base64 characters plus the 22-character prefix. Use it as background-image: url("data:image/png;base64,...").

Logo in an HTML email

Embedding a small JPEG logo.

Input
logo.jpg
Result
A string starting data:image/jpeg;base64,/9j/

JPEG data URIs start with /9j/, the encoded JPEG marker. Note that some email clients, including Gmail, block data URI images, so test before sending.

Limitations
Only the first 500 characters are displayed; use Copy to get the full string. There is no option to output raw Base64 without the data URI prefix. Very large images produce very long strings that can be slow to paste into editors.
Assumptions
The file's MIME type is detected by the browser from the file.
Privacy
The image is read and encoded in your browser and is not uploaded anywhere.

Frequently asked questions

When is embedding an image as Base64 useful?+

For small icons and images where avoiding a separate file or request matters more than the roughly 33% larger size, such as CSS icons or self-contained HTML files.

Does Base64 encoding reduce image quality?+

No. It is a lossless text representation of the exact same file bytes, so the image is identical when decoded.

How do I use the result in HTML?+

Paste it as the src: <img src="data:image/png;base64,..." alt="...">. In CSS, wrap it in url("...").

Why is only part of the string shown?+

Long strings can freeze the page, so the panel shows the first 500 characters followed by an ellipsis. The Copy button always copies the complete data URI.

Why is the Base64 version bigger than my file?+

Base64 uses 4 text characters for every 3 bytes, so the output is about one third larger than the original.

Related tools