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-09Try it right now — free, no sign-up
Use the embedded tool directly in your browser. Your data never leaves your device.
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
- Open the tool — Visit the Image to Base64 Converter.
- Upload your image — Select or drag a PNG, JPG, GIF, or SVG file.
- Copy the data URI — Get the full
data:image/png;base64,...string. - 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/pngfor PNG,data:image/jpegfor JPG,data:image/svg+xmlfor 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
- Base64 Encoder — Encode text strings (not just images) to Base64
- HTML Entity Encoder — Encode HTML for templates using embedded images
- CSS Minifier — Minify CSS that includes Base64 background images
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
How to Encode Base64 Online: A Complete Guide
Learn how to encode and decode Base64 strings online in seconds. Step-by-step tutorial with real-world use cases for APIs, images, and email attachments.
How-To GuideHow to Format JSON Online: Step-by-Step Tutorial
Format, validate, and minify JSON online for free. Step-by-step guide with real-world examples for APIs, configs, and debugging.
How-To GuideHow to Decode JWT Online in 3 Steps
Decode and inspect JSON Web Tokens online in seconds. Learn what's inside a JWT — header, payload, and signature — with real examples.
How-To GuideHow to Minify CSS Online: Save File Size Fast
Minify your CSS online for free to reduce file size and speed up page load times. Step-by-step guide with before/after size comparisons.