About this tool
This image to Base64 converter turns pictures into Base64 text that you can embed directly in HTML, CSS, Markdown, JSON or email templates as a data URI. Choose one or more images and the tool shows ready-to-paste snippets: the full data URI, the bare Base64 string, an <img> tag with the image's width and height, a CSS background-image rule and a Markdown image.
It also works the other way round. Paste a data URI or Base64 code and the tool decodes it, shows the image with its type and dimensions, and lets you download it as a file. Images are read and encoded only in your browser.
How it works
Base64 writes every 3 bytes of the file as 4 printable characters, so the text is about a third larger than the image: characters for bytes. A data URI adds a short header with the media type, for example data:image/png;base64, followed by the code.
The image type is read from the file's first bytes, not just from its name, so a PNG renamed to .jpg still gets the correct image/png header. SVG files are encoded as Base64 too; for the HTML snippet, the width and height come from the image itself and the alt text from the file name, which you should replace with a real description.
For decoding, the tool accepts a complete data URI, a CSS url(…) or HTML img snippet that contains one, percent-encoded SVG data URIs and plain Base64, including the URL-safe alphabet with - and _. Line breaks and spaces in the code are ignored.
Example
A 1,500-byte PNG icon becomes , which is 2,000 Base64 characters. With the 22-character header data:image/png;base64, the data URI is 2,022 characters long, about 35% more than the file. Pasted into a stylesheet, it saves one HTTP request for a tiny icon.
A 300 KB photo, on the other hand, becomes about 400 KB of text. That text must be downloaded again with every page or stylesheet that contains it and cannot be cached on its own, so for a large image a normal file link is faster.
Assumptions and limits
Each image can be up to 10 MB, and up to 20 images are processed at a time. Supported formats are PNG, JPG, GIF, WebP, SVG, AVIF, BMP and ICO; browsers that cannot display AVIF or ICO still produce the code. The text box shows the first 20,000 characters of very long codes, while Copy and Download include everything. File sizes use 1 kB for 1,024 bytes. Images are not resized, compressed or converted. Your files are processed only in your browser and are not uploaded.
Frequently asked questions
How do I convert an image to Base64?
Choose or drop the image, then pick the output you need: Data URI for an src attribute or url(), Base64 only for JSON or APIs, or a ready HTML, CSS or Markdown snippet. Copy it or download it as a text file.
How do I use a Base64 image in HTML or CSS?
In HTML, put the data URI in the src attribute of an img element: <img src="data:image/png;base64,…" alt="…">. In CSS, use it inside url(), for example background-image: url("data:image/png;base64,…"). The HTML and CSS outputs of this tool are ready to paste.
Why is the Base64 code larger than the image?
Base64 represents 3 bytes with 4 characters, so the code is about 33% larger than the file, plus a few characters for the data URI header and padding. Compression by the web server (gzip or Brotli) recovers part of the difference.
When should I not inline images as Base64?
Inline only small images, such as icons under a few kilobytes. Larger Base64 images make HTML and CSS files heavier, delay rendering and cannot be cached separately by the browser, so they are downloaded again with every page that contains them.
How do I turn Base64 back into an image?
Switch the direction to Base64 to image and paste the code. The tool accepts a full data URI, a CSS or HTML snippet that contains one, or plain Base64. It shows a preview with the detected type and dimensions, and Download image saves it with the right file extension.
Link with your values
Add these parameters to this page’s address to open it with the values filled in, for example to share a calculation or to link to it from an AI assistant. The result is calculated in the browser: the page HTML shows an example for the default values, and the tool sets the data-url-params attribute once the link’s values are applied.
| Parameter | Value | If omitted |
|---|---|---|
directionDirection | one of: encode, decode | default encode |
outputOutput | one of: data_uri, base64, html, css, markdown; used with direction = encode | default data_uri |
data_uriData URI or Base64 | not accepted in links: enter it on the page |
Examples
?output=html?direction=decode
Write decimals with a point. Encode a space as %20, + as %2B, # as %23 and & as %26.
Result elements: [data-result-block="image-base64"]