How-To Guide

How to Convert Images to Base64 Online: Step-by-Step Guide

Convert PNG, JPG, GIF, and SVG images to Base64 data URIs online for free. Learn to embed images in HTML, CSS, and JSON without extra HTTP requests.

Published 2026-03-09

Try it right now — free, no sign-up

Use the embedded tool directly in your browser. Your data never leaves your device.

Open Tool →

Embedding images as Base64 data URIs eliminates HTTP requests, enables offline-capable web apps, and simplifies email template images. This guide shows you how to convert any image to Base64 online — no command-line tools or Python scripts needed.

What is a Base64 Image Data URI?

A Base64 data URI is a way to embed binary image data directly in text-based formats like HTML, CSS, or JSON. Instead of referencing an external file:

<!-- External image: requires HTTP request -->
<img src="/images/logo.png">

<!-- Base64 data URI: no HTTP request needed -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...">

Step-by-Step: How to Convert an Image to Base64

  1. Open the tool — Visit the Image to Base64 Converter.
  2. Upload your image — Select or drag a PNG, JPG, GIF, or SVG file.
  3. Copy the data URI — Get the full data:image/png;base64,... string.
  4. Use in HTML, CSS, or JSON — Paste directly where an image URL would go.

Real-World Use Cases

1. Embedding Icons in HTML Emails

Many email clients block external images by default. Embedded Base64 images always display:

<!-- External image: may be blocked in email clients -->
<img src="https://example.com/logo.png" width="100">

<!-- Base64 embedded: always displays, no external request -->
<img src="data:image/png;base64,iVBORw0KGgoAAAA..." width="100"
     alt="Company Logo">

2. Embedding Small Icons in CSS

/* CSS background-image with Base64 SVG icon */
.icon-checkmark {
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...");
  background-repeat: no-repeat;
  background-size: 16px 16px;
  width: 16px;
  height: 16px;
}

3. Sending Images via API

REST APIs that don't support multipart file uploads can accept Base64-encoded images in JSON:

# POST /api/profile with JSON body
import base64
import requests

with open("avatar.jpg", "rb") as f:
    image_data = base64.b64encode(f.read()).decode("utf-8")

response = requests.post(
    "https://api.example.com/profile",
    json={
        "username": "alice",
        "avatar": f"data:image/jpeg;base64,{image_data}"
    }
)

When NOT to Use Base64 Images

  • Large images — Base64 increases file size by ~33%. Images over 5KB are better served from a CDN with caching headers.
  • Frequently changing images — Embedded images can't be independently cached. User avatars and product photos change often — use URLs instead.
  • Images reused across pages — A shared logo embedded as Base64 in every page means the browser can never cache it across pages. One external URL serves all pages.

Common Mistakes to Avoid

  • Embedding large images — Keep Base64 images under 5KB. Use a CDN for larger images.
  • Forgetting the data URI prefix — The full format is data:[mediatype];base64,[data]. Missing the prefix causes the browser to interpret it as a URL.
  • Using the wrong MIME type — Use data:image/png for PNG, data:image/jpeg for JPG, data:image/svg+xml for SVG. Wrong MIME types cause display errors.
  • Storing Base64 in databases — Store image files in object storage (S3, Cloudflare R2) and store the URL in the database instead.

Related Tools

Ready to try it?

Free online tool — no download, no account, works in your browser.

Open Convert Images to Base64 Online: Step-by-Step Guide Tool →

Related Articles