Skip to content
HNarzędzia
en
Categories

Image to Base64 and data URI converter (and back)

Encode an image as Base64 and paste it straight into HTML, CSS, JSON or an email template - or paste Base64 and see which image it contains.

  • Free
  • No sign-up
  • Private
  • Runs locally

Drag & drop files here

or click to choose from your device

JPG, PNG, WebP, GIF, SVG, ICO, AVIF · one file · you can also paste (Ctrl+V)

How to convert an image to Base64

  1. 1.

    Choose an image

    Drop the file onto the box, pick it from your device or paste it from the clipboard (Ctrl+V).

  2. 2.

    Pick the output format

    Data URI, raw Base64, a ready CSS rule, an HTML <img> tag or Markdown.

  3. 3.

    Copy the code

    Click “Copy” or download the result as a .txt file.

  4. 4.

    Decode (optional)

    In “Base64 → image” mode, paste the text, check the preview and download the file.

What are Base64 and data URIs?

Base64 writes binary data (such as a PNG file) using 64 text-safe characters: A-Z, a-z, 0-9, “+” and “/”. Every 3 bytes of the file become 4 characters, so the text is about 33% longer than the file: a 30 KB image turns into roughly 40 KB of text (exactly 4 × ⌈n ÷ 3⌉ characters).

A data URI is Base64 with a prefix that states the data type, for example data:image/png;base64,iVBORw0KGgo…. The browser treats it like a file address, so you can put it in an image’s src or in a CSS url().

When should you embed images as Base64?

  • Yes: small icons and patterns (up to a few KB), images in email templates, single-file HTML pages without external assets, data in JSON or API payloads, tests and prototypes.
  • No: photos and large graphics. Base64 adds 33% to the size, is not cached separately by the browser and blocks CSS and HTML parsing. Serve large images as normal files, ideally WebP.

For SVG, a URL-encoded SVG string is often shorter than Base64 and works just as well in CSS.

How long will the encoded image be?

Base64 length is 4 × ⌈n ÷ 3⌉ characters, where n is the file size in bytes. A data URI adds its prefix, e.g. data:image/png;base64, is 22 characters.

FileSizeBase64 lengthEmbed it?
SVG icon1 KB (1024 B)1,368 charactersyes
PNG icon 64×644 KBabout 5,500 charactersyes
PNG logo30 KBabout 41,000 charactersin emails rather than on websites
JPG photo500 KBabout 683,000 charactersno

Above 100 KB the tool shows a warning. The file is encoded byte for byte without re-compression, so the Base64 also contains the photo’s EXIF metadata (including GPS). Before embedding a photo, strip it with the EXIF remover and shrink it with the image compressor.

Common decoding problems

  • Truncated text - Base64 copied from logs or a console is often cut off. Typical symptom: an “invalid Base64” message or an image cut in half.
  • Spaces and line breaks - removed automatically, so you can paste text wrapped every 76 characters as in MIME emails.
  • URL-safe variant - “-” and “_” are turned back into “+” and “/”, and missing “=” padding is added.
  • Code snippets - paste a whole CSS rule with url(…) or an <img src="…"> tag and the tool extracts the data itself.
  • Data that is not an image - the type is detected from the file signature (JPG, PNG, GIF, WebP, BMP, ICO, AVIF, SVG), not just the data: prefix. Base64 containing a PDF or plain text is rejected.

Usage examples

<img src="data:image/png;base64,iVBORw0KGgo…" alt="Logo">

.icon {
  background-image: url("data:image/svg+xml;base64,PHN2Zy…");
}

![Logo](data:image/png;base64,iVBORw0KGgo…)

Frequently asked questions

Why is Base64 larger than the file?

+
Base64 encodes 3 bytes as 4 text characters, so the result is about 33% longer than the original. Gzip or Brotli compression on the server partly offsets this.

How do I convert Base64 back to an image?

+
Switch to “Base64 → image” and paste the text, with or without the data: prefix. You will see a preview and can download the file in its original format.

Are SVG files supported?

+
Yes. SVG is encoded with the image/svg+xml type, and when decoding the tool recognises it from the content.

Is Base64 encryption?

+
No. Base64 is just an encoding and anyone can decode it. Never use it to hide confidential data.

Are my files uploaded to a server?

+
No. Encoding and decoding happen in your browser.

Updated: