Data URI · CSS · HTML · Decode

Image to Base64 Converter

An image as one line of text.
And Base64 text back as an image.

Turn a PNG, JPG, SVG, WebP or GIF into a Base64 data URI, a CSS background or an HTML img tag, ready to copy. Or paste Base64 from an API, email or code to see the image and save it with the right file type.

  • Both ways Encode and decode
  • Code types Data URI · CSS · HTML
  • Formats PNG, JPG, SVG and more
  • File size limit 10 MB per image

Built & Designed by Bhavin J. Sheth Last updated:

YOUR WORKSPACE

Image ⇄ Base64

Add an image to encode

Drop, paste (Ctrl + V) or choose one image.

PNG · JPG · SVG · WebP · GIF · AVIF · ICO · 10 MB

Add an image to get its Base64 code. It stays in this browser.

Pick the code type

The same Base64, wrapped for where it goes.

All code types hold the identical image; only the text around the Base64 changes.

Code type Looks like Use it in
Data URI data:image/png;base64,iVBOR… An img src, a Markdown image, email HTML or anywhere a URL is expected.
Base64 only iVBORw0KGgo… JSON and API fields that ask for the Base64 text without a prefix.
CSS background-image background-image: url("data:…"); A stylesheet, for small icons and patterns.
HTML <img> tag <img src="data:…" alt="…" width height /> A page or email signature; width and height are filled in for you.
SVG without Base64 data:image/svg+xml,%3Csvg… CSS icons; usually shorter than Base64 for SVG files.

Before you paste it

Small images, short code.

Shrink the file first

Base64 is about a third larger than the file, so compress or resize the image before you encode it.

The image is not changed

The exact bytes of your file are encoded, so decoding gives back the same file with the same quality.

SVG has a shorter option

For SVG, choose SVG without Base64; the text is URL-encoded instead and is usually smaller.

Not for big photos

Large Base64 images slow pages down because browsers cannot cache them separately. Keep them for icons and logos.

Code length, measured

Four images, their real code size.

Measured with this tool. Characters are for the Data URI, including the data:…;base64, prefix.

Image File size Data URI length
64 × 64 PNG icon 350 bytes 490 characters
SVG logo, Base64 238 bytes 346 characters
Same SVG, without Base64 238 bytes 280 characters
3000 × 4000 JPG photo 325,290 bytes 433,743 characters (+33%)

A 325 KB photo becomes more than 430,000 characters, which is why Base64 suits icons and small logos, not page photos.

How it works

Bytes to text and back, on your device.

Encode and decode in the browser

The image type is read from the file's first bytes, so the data URI gets the right image/… label even if the file was renamed.
The browser turns every 3 bytes into 4 Base64 characters; the picture is never re-saved.
Decoding reverses it: spaces, line breaks and URL-safe characters are cleaned, then the bytes are checked to be a real image.
You get the code or the image file right here. Nothing is sent to a server.

Everyday uses

Where an image has to be text.

Task Setup What to check
An Indian app or portal API returns a photo or signature as Base64 Base64 → Image · paste the field value The type is detected from the data, so it saves as .jpg or .png correctly.
Sending an image in a JSON API request Image → Base64 · Base64 only Check the size limit of the API; compress the image first if needed.
A logo in an email signature HTML <img> tag · small PNG Some email apps block data URI images; test by sending one to yourself.
A CSS icon without an extra file SVG · SVG without Base64, or CSS background-image Keep icons under a few KB so the stylesheet stays light.
An image stuck inside HTML or a .txt file Base64 → Image · Open a .txt file or paste the code The first data URI in the text is used.

Troubleshooting

When the code does not work.

"Cut short" or "cannot appear"

Part of the code is missing or extra.

  • Copy the whole value again.
  • Remove quotes or JSON around it.
  • Or paste the full data URI.

"This Base64 is not an image"

The text decodes, but to another file type.

  • It may be a PDF or other file.
  • Check you copied the image field.
  • Some APIs encode twice; decode once more.

The image does not show on my page

The code may be in the wrong place.

  • Use Data URI inside src="…".
  • Use Base64 only for JSON fields.
  • Check that the code was not shortened.

The code is too long

The image file is large.

  • Compress it to a few KB first.
  • Resize it to the shown size.
  • For SVG, choose SVG without Base64.

Base64 image questions

Before you paste the code

How do I convert an image to Base64?

Add or paste the image, choose the code type (Data URI, Base64 only, CSS or HTML) and press Copy code or Download .txt. The code appears as soon as the image is read.

How do I convert Base64 back to an image?

Open Base64 → Image, paste the code or a full data URI, and press Show image. The tool finds the real file type, shows a preview, and Download image saves it with the right extension.

What is the difference between Base64 and a data URI?

Base64 is only the encoded text. A data URI adds a prefix such as data:image/png;base64, so browsers know it is a PNG image. Use the data URI in HTML and CSS, and plain Base64 where an API asks for it.

Why is the Base64 code bigger than my image?

Base64 writes every 3 bytes as 4 characters, so the code is about 33% larger than the file. The prefix and any HTML or CSS around it add a little more.

Does converting to Base64 reduce image quality?

No. The file's bytes are encoded exactly as they are, without re-saving the picture, so decoding the code gives back the identical file.

Which image formats can I use?

PNG, JPG, SVG, WebP, GIF, AVIF, BMP, ICO and HEIC, up to 10 MB. HEIC is encoded correctly, but most browsers other than Safari cannot show it, so the preview may be missing.

Should I use Base64 images on my website?

Only for small icons and logos of a few KB. Large Base64 images make HTML and CSS heavier and cannot be cached on their own, so normal image files load faster for photos.

Can I decode URL-safe Base64 or code with line breaks?

Yes. Spaces and line breaks are removed, - and _ are read as + and /, and missing = padding is added. Code inside CSS url(…) or an HTML src="…" also works.

Why does the saved image have a different extension?

The extension comes from the image data, not the label. If the code says image/png but the data is a JPG, it is saved as .jpg and a note explains why.

Is my image or code sent to a server?

No. Encoding and decoding both happen in this browser tab, and nothing is saved after you close the page. Copy or download your code before you leave.

Ready to convert your image?

Back to the converter, or browse the image tools and the full tools directory.

Back to workspace ↑