Base64 Encoder

Image to Base64 Converter

Drop any image and get the base64 string, data URI, ready-to-paste HTML <img> tag, and CSS `background-image`. Everything runs locally.

Last updated: August 2026

Raw + URI

All Formats

HTML + CSS

Ready Code

PNG, JPG, SVG, GIF

Support

Private

No Uploads

Drop any image here

PNG, JPG, WebP, GIF, SVG, BMP or ICO. Your file never leaves this device.

Choose image

How to convert an image to base64

Five steps, all running locally in your browser.

01

Drop your image

PNG, JPG, WebP, GIF, SVG, BMP or ICO. Nothing is uploaded, it stays on your device.

02

Choose an output format

Raw Base64, Data URI, HTML img tag, or CSS background-image.

03

Check the size overhead

Original vs encoded size shown. A warning appears above 10KB encoded.

04

Verify the HTML tag before pasting

If width and height show as 0, edit those values before using the snippet.

05

Copy or download

Copy to clipboard, or download the current output as a .txt file.

When to use base64 for images and when not to

Base64 encoding adds around 33% to the file size. A 100KB image becomes 133KB as a base64 string. Understanding when that tradeoff is worth it saves you from accidentally making pages slower.

Good uses for base64

  • Small icons, logos and UI sprites under 10KB
  • Favicons embedded in HTML to avoid an extra request
  • Images sent as part of JSON API payloads
  • SVG icons embedded in CSS to avoid CORS issues
  • Email template images (some email clients block external images)

When to avoid base64

  • Photos and large images above 10KB
  • Hero images, product photos and banners
  • Any image that should be browser-cached between page visits
  • Images used across many pages (defeats caching entirely)
  • Anywhere page load speed and Core Web Vitals matter

The four output formats and what each is for

Raw Base64

iVBORw0KGgoAAAANSUhEUg...

When you are storing the value in a JSON field, database column or API payload where you will construct the full data URI yourself. Also used in CSS custom properties and some framework-specific contexts.

Data URI

data:image/png;base64,iVBORw0KGgo...

The most versatile format. Works directly in HTML src attributes, CSS url() values, JavaScript src assignments and anywhere a browser can render an image from a string.

HTML img tag

<img src="data:image/png;base64,..." width="200" height="150" alt="" />

Ready to paste directly into HTML. Width and height attributes are included from the detected image dimensions, but check them first: they can come back as 0 for certain SVG files if the dimension check couldn't decode the image. You will also want to add a meaningful alt attribute describing the image.

CSS background-image

.element { background-image: url("data:image/png;base64,..."); }

Ready to paste into a CSS rule. Useful for embedding decorative images, patterns and icons directly in a stylesheet without an extra HTTP request.

Common image to base64 mistakes

Pasting the HTML tag without checking for width="0" height="0"

When the tool's dimension check fails, usually for certain SVGs, it falls back to 0. The image info strip hides this, but the HTML img tag output shows the raw values exactly as generated. A 0x0 image is invisible on the page, always glance at the width and height in the snippet before pasting.

Assuming base64 shrinks or compresses the image

It doesn't, and it isn't meant to. Base64 is a lossless text encoding that adds roughly 33% to the file size. If you need a smaller file, compress the image first, then encode the compressed result.

Base64-encoding a large photo because it's convenient

The 10KB warning banner isn't a suggestion to ignore. Inlining a large image blocks page rendering, adds 33% overhead, and can't be cached separately by the browser the way a normal image file can. Serve large images from a URL instead.

Leaving the placeholder alt="" in the generated HTML tag

The HTML output always includes an empty alt attribute as a starting point. Replace it with a real, descriptive alt text before using the snippet, empty alt should only stay if the image is genuinely decorative.

Trying to convert a HEIC, AVIF or TIFF file here

Those formats aren't in the accepted list. Convert to PNG, JPG or WebP first using one of the format converters, then encode the result to base64.

Why use ImgTweak?

Runs entirely in your browser
No uploads, ever
Four output formats, switch freely between them
Automatic size warning above 10KB encoded
Copy to clipboard or download as .txt
Free forever, no account needed

Frequently asked questions

What is base64 image encoding?

Base64 encoding converts binary image data into a string of printable ASCII characters. This lets you embed image data directly inside HTML, CSS, JSON and other text-based formats without needing a separate image file. The encoded string can be used anywhere a file URL would normally go, such as the src attribute of an img element or the url() value in CSS.

Why does the HTML img tag sometimes show width="0" height="0"?

This tool reads the image's dimensions by decoding it a second time, separately from the base64 encoding itself. For some SVG files and a few other unusual images, that secondary decode can fail even though the base64 encoding succeeded perfectly. When that happens, width and height fall back to 0. The image info strip on this page hides the dimensions when that occurs, but the HTML img tag output does not, it will show width="0" height="0" exactly as generated. Always check the width and height values before pasting the HTML snippet directly, an image with 0x0 dimensions renders as invisible.

What is the difference between raw base64 and a data URI?

Raw base64 is just the encoded string, for example iVBORw0KGgo... A data URI is the full string including the MIME type prefix: data:image/png;base64,iVBORw0KGgo... You need the full data URI format to use the string directly in an img src attribute, CSS url(), or anywhere a browser needs to render the image. Raw base64 is used when you are storing the string in JSON, a database, or an API payload where you will add the prefix yourself later.

Does base64 encoding affect image quality?

No. Base64 is a lossless encoding method. It represents the exact binary data of the original file as text characters. Decoding the base64 string produces the original file byte for byte. No pixels are changed and no quality is lost.

Why is the encoded file larger than the original?

Base64 encoding converts every 3 bytes of binary data into 4 text characters. This means the encoded output is always approximately 33% larger than the original binary file. A 100KB image becomes roughly 133KB as a base64 string. This is an inherent property of the encoding format and applies to all base64 encoded data.

When should I use base64 for images?

Base64 is best for small images under 10KB such as icons, small logos, favicons and UI sprites. For these, embedding base64 eliminates an HTTP request which can make the page faster. For larger images, base64 is usually a bad choice because the 33% size overhead makes files larger, the data is not cached separately by the browser, and the inline content blocks page rendering. Large images should be served as separate files from a CDN.

Can I download the result instead of only copying it?

Yes. A Download .txt button next to Copy to clipboard saves whichever output tab is currently active, raw base64, data URI, HTML tag, or CSS rule, as a plain text file named after your original image.

Is my image uploaded to a server?

No. The encoding uses the browser's built-in FileReader API which reads and encodes the file entirely on your device. Nothing is sent to any server. You can disconnect from the internet after the page loads and the tool still works.

What image formats are supported?

PNG, JPEG, WebP, GIF, SVG, BMP and ICO are all supported. The output data URI includes the correct MIME type for each format so the browser knows how to render it. HEIC, AVIF and TIFF are not supported here, convert to one of the supported formats first if you're starting from one of those.

Ready to encode your image?

No sign-up. No uploads. Drop your image above and get the code in seconds.