Image to Base64 Converter

Turns an image into Base64 text you can put inside HTML, CSS or JSON. Explains which output format goes where and when inlining an image makes a page slower instead of faster.

The output will appear here.
Advertisement icyabmod — get a website for your business, design it on a live demo

How Image to Base64 Converter works

Turns an image into Base64 text you can put inside HTML, CSS or JSON. Explains which output format goes where and when inlining an image makes a page slower instead of faster.

Input Image file
Output Base64 / Data URI
Works done 0

How to use it

An image to Base64 converter turns a picture file into plain text you can write directly into HTML, CSS or JSON, so the image travels inside the page or the data instead of as a separate download. This tool reads JPG, PNG, WebP, GIF, SVG and other images in your browser and gives you a data URI, raw Base64, a CSS rule or an HTML tag.

How to convert an image to Base64

  1. Add the image with the file picker or drag it onto the page; the limit is 10 MB.
  2. Pick the output format: data URI, Base64 only, CSS or HTML.
  3. Check the preview, the original file size and the length of the Base64 text.
  4. Copy the result to the clipboard, or download it as a .txt file when it is long.
  5. Paste the code into your HTML template, stylesheet or JSON request body.

The four output formats and where each fits

FormatStarts likeTypical use
Data URIdata:image/png;base64,iVBORw0KGgo…Anywhere a URL is expected: src, url(), a JavaScript variable
Base64 onlyiVBORw0KGgo…APIs that take the image as a Base64 field, database records, config files
CSSbackground-image: url("data:image/svg+xml;base64,…")Small icons and patterns used as backgrounds without an extra request
HTML<img src="data:image/jpeg;base64,…" alt="">Single-file HTML reports, offline demos, document templates

The alt attribute in the HTML output is left empty; if the image carries meaning, write a description yourself. For JSON payloads, check the API documentation: some services want raw Base64 and reject the data: prefix as invalid, others expect the full data URI.

Why the Base64 text is bigger than the file

Base64 writes every 3 bytes as 4 characters, so the text is roughly a third longer than the original file. A 6 KB icon becomes about 8 KB of text, and a 300 KB photo turns into well over 400 KB. The tool encodes the file's bytes exactly as they are, with no recompression or resizing. For a shorter result, shrink the image first with the image compressor or the image resizer, then bring it here.

The MIME type is detected from the signature in the file's first bytes, not from its name. A PNG that was accidentally renamed to .jpg still gets the correct image/png label in the data URI. If the signature is not recognized, the file type reported by the browser is used.

Should you inline the image or keep a separate file?

An inlined image saves one HTTP request, but it is not free. The browser cannot cache it on its own, so it is downloaded again every time the HTML or CSS file containing it is fetched. As a rough rule, images under 10 KB are good candidates for inlining.

  • Good to inline: small icons, loading spinners, tiny logos on a one-page landing site, single-file HTML reports that are emailed or opened offline, and test fixtures.
  • Do not inline: large photos, logos and backgrounds repeated on every page of a site, the hero image that is the largest element on the page, responsive images served in several sizes, and images that change often.

A note on SVG icons: SVG is already text, so Base64 only makes it longer. An SVG embedded in CSS with URL encoding usually comes out shorter. Base64 is more practical when every character must be safe, for example when the SVG travels inside a JSON field.

Base64 images in email signatures

Base64 is often suggested for putting a logo in an email signature, but email clients behave inconsistently. Some webmail services and corporate clients do not display images embedded as data URIs, block them or show them as attachments. Before you start using the signature, send test messages to yourself and to a few addresses on different services. If the image does not appear, hosting the logo on a web server and linking it with a normal URL is the more reliable route.

Related tools and privacy

To see which image a Base64 string contains, the Base64 to image converter does the reverse. If you need to encode or decode text rather than images, the Base64 encoder and decoder handles UTF-8 correctly. Our article on what Base64 is explains how the encoding works.

The file you choose is read and encoded by JavaScript in your browser; the file itself is not transmitted to our server, and the page only increments an anonymous usage counter. That matters when you are working with an unreleased product shot or a client's logo.

Advertisement icyabmod — 7 sections × 10 designs and 10 color palettes: design your site yourself, preview ready in 48 hours

Frequently asked questions

Drag the image onto the area on this page or add it with the file picker, then choose the output format. The tool reads the file in your browser and produces the Base64 text immediately. Copy it into your HTML, CSS or JSON. If you prefer to do it in code, the readAsDataURL method of the browser's FileReader object produces the same data URI format.

Raw Base64 is just the encoded data. A data URI puts a prefix in front of it that declares the type, such as data:image/png;base64, followed by the data. Browsers need the data URI when the image is shown through src or url(). When sending an image to an API, most services expect raw Base64, and adding the prefix can trigger an invalid data error.

Base64 writes binary data using only 64 safe characters, each carrying 6 bits. Every 3 bytes therefore become 4 characters, and the text ends up about 33 percent longer than the file. Even if the server compresses the response with gzip or similar, the gap does not fully close. That is why large photos are better served as separate files.

As a general rule, small icons and decorative images under about 10 KB are suitable. Larger images bloat the HTML or CSS file, delay the first render and cannot benefit from the browser cache. If the same image appears on many pages, keeping it as a separate file is often better even when it is small.

No. Base64 is an encoding, not encryption. It needs no key, and anyone can turn the text back into the image in seconds. Embedding an image in code does not hide it or protect it from being copied. Do not use it to place images that must stay private on public pages; access control has to happen on the server.