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.

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

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 image dimensions to prevent layout shift. You will 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.

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.

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.

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.