Skip to content

Image to Base64

Encode an image as Base64 text in a .txt file, with a data URI, an HTML img tag and a CSS background rule ready to paste.

or drag and drop them here · up to 10 MB per file

Your files are processed on this device and never uploaded.

Instant conversion

There is no upload or server queue, so conversion starts the moment you drop a file and finishes as fast as your device can process it.

Your files stay private

Files are processed entirely inside your browser. They are never sent to, stored on, or seen by any server.

Nothing to install

Works on Windows, macOS, Linux, Android and iOS in any modern browser. No software, no extensions, no account.

How to use Image to Base64 (data URI)

  1. 1

    Click "Choose files" or drop images in. PNG, JPG, SVG, GIF, WEBP and ICO work, and you can add several at once.

  2. 2

    Under "Options", pick what to write: the data URI with HTML and CSS snippets (default), the data URI only, or the bare Base64.

  3. 3

    Click "Convert" and download the .txt. Open it in a text or code editor and copy the line you need.

When to use it

  • One self-contained HTML file: logos in email signatures, HTML reports viewed offline, or internal pages where you cannot host image files
  • Small icons inside CSS: check marks, arrows and background patterns without an extra request
  • Images in APIs and JSON: testing an API that takes Base64 images, or putting a small picture in a config file
  • Markdown with the pictures inside: sharing a single document instead of a folder of images

What the text file contains

With the default option, logo-base64.txt holds three blocks:

Block Looks like Paste it into
Data URI data:image/png;base64,iVBOR... Anywhere an image address goes
HTML <img src="data:..." width="32" height="32" alt=""> HTML, or the HTML mode of an email signature editor
CSS .image { background-image: url("data:..."); } A stylesheet or style tag

The HTML and CSS include the picture’s width and height in pixels so the page can reserve its space. SVG sets its own size, so it is written without one. Rename .image and fill in alt="" to suit your page.

Mind the size

Base64 writes every 3 bytes as 4 characters, so the text is about 33% larger than the file.

Original image Base64 length Good fit?
2 KB icon about 2,700 characters Great
20 KB logo about 27,000 characters Fine
200 KB photo about 270,000 characters Better as a file
2 MB photo about 2.7 million characters May freeze editors

A picture in a data URI cannot be cached on its own, so it is read again on every page that contains it. If the same image appears on many pages, a normal file is faster. Shrink large pictures first with Compress image or Resize image.

Tools that go well with it

What is a TXT file?

A TXT file contains plain text only: no fonts, layout, images or hidden markup. That makes it the most portable document format there is. It opens on every device and in every text editor, is easy to search and process with scripts, and takes up very little space.

The trade-off is that formatting such as bold text, tables and pictures cannot be stored. Line breaks and blank lines are the only structure a TXT file has.

Frequently asked questions

Should I turn large photos into Base64?

You can, but it is rarely a good idea. Base64 is about a third larger than the file, so anything over a few hundred KB becomes hundreds of thousands of characters that weigh down the HTML or CSS and slow editors. It suits icons, logos and small patterns of a few KB to a few tens of KB; serve big photos as normal image files, or compress them first.

When do I want the data URI only, or Base64 only?

A data URI starts with data:image/png;base64, and can go straight into an HTML src or a CSS url(). Bare Base64 has no prefix and is what APIs, JSON fields and config files usually expect.

Does it lose quality?

No. The file is not re-saved; its bytes are written out as text, so decoding the Base64 gives back exactly the same file.

Why can't I add HEIC photos?

Most browsers cannot show HEIC in a web page, so a HEIC data URI would not display anywhere. Convert it with HEIC to JPG first.

What if the extension does not match the real format?

The first bytes of the file are read to find the real format, so a PNG that is named .jpg still gets image/png in its data URI.

Are my images uploaded?

No. The encoding happens inside your browser and the images are never sent anywhere.

Related converters