Ttooleras
🖼️

Image to Base64

Image Tools

Convert any image to Base64-encoded data URI for embedding directly in HTML src, CSS background, or JSON data fields.. Free, private — all processing in your browser.

Advertisement

The Image to Base64 tool converts any image into a Base64-encoded data URI that can be embedded directly into HTML, CSS, JSON, or email templates without needing a separate file. Data URIs are useful when you want a self-contained HTML file, want to embed small images in CSS without HTTP requests, need to include images in JSON API responses, or want to simplify email templates by eliminating image file attachments.

Upload an image and the tool produces the data URI in the format: data:image/png;base64,iVBORw0KGgoAAAANSUhEUg... Copy the full URI and paste it into your HTML img src, CSS url(), or JSON string. For large images, data URIs are inefficient (base64 increases size by ~33%) but for small icons, backgrounds, or images that must be inline, they\u2019re practical. All encoding runs in your browser so private images stay local.

Image to Base64 — key features

All common formats

PNG, JPEG, WebP, GIF, SVG — each produces the correct MIME type in the data URI.

Copy-ready output

Full data:image/X;base64,... URI copies with one click.

Size estimate

Shows original file size and base64 size (~33% larger) so you know the tradeoff.

MIME auto-detect

Determines correct MIME type from image format.

Preview

Verify the data URI by showing the rendered image from the generated string.

CSS snippet

Optional output as CSS snippet: background-image: url(data:...).

HTML snippet

Optional output as HTML img tag with embedded src.

Client-side only

Images are encoded in your browser; nothing is uploaded.

How to use the Image to Base64

  1. 1

    Upload image

    Drag or click to select any image file.

  2. 2

    See base64 output

    The full data URI appears with copy button.

  3. 3

    Verify preview

    The preview renders the image from the base64 string to confirm correctness.

  4. 4

    Pick output format

    Raw base64, full data URI, HTML img tag, or CSS snippet.

  5. 5

    Copy

    One-click copy the selected format for paste into your code.

Common use cases for the Image to Base64

Web development

  • Inline CSS backgrounds: Embed small icons as CSS background-image data URIs for self-contained stylesheets.
  • Single-file HTML: Create portable HTML documents with embedded images that don’t require external files.
  • Placeholder graphics: Use tiny base64-encoded placeholders while lazy-loading real images.

Email and templates

  • Email image embedding: Avoid attachment issues by embedding small images directly in HTML email.
  • Report generation: PDF or HTML reports with embedded charts and graphics for portability.
  • Template distribution: Self-contained templates without separate image files.

APIs and data

  • JSON API responses: Include image data in API responses for applications that need images inline.
  • Avatar data: Store user avatars as base64 in JSON user profiles.
  • Form uploads: Pre-process images to base64 before form submission in specific workflows.

Image to Base64 — examples

Tiny icon

1KB PNG to data URI.

Input
16x16 favicon PNG
Output
data:image/png;base64,iVBORw0KG... (about 1.3KB encoded)
ready to paste into <img src> or CSS url()

CSS background

Embedded in stylesheet.

Input
small logo PNG
Output
.logo { background: url(data:image/png;base64,iVBOR...); }

HTML img tag

Self-contained image.

Input
chart screenshot
Output
<img src=\"data:image/png;base64,iVBOR...\" alt=\"chart\" />

JSON embedded

Image in API response.

Input
user avatar 100x100
Output
{ \"avatar\": \"data:image/jpeg;base64,/9j/4AAQSk...\" }

Size comparison

File size vs base64 size.

Input
100 KB JPEG
Output
original: 100 KB
base64: approximately 133 KB (+33%)

Technical details

Data URI scheme (RFC 2397) encodes resource data directly in a URL-like string:

data:[<mediatype>][;base64],<data>

For images:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA...

The prefix identifies the MIME type (image/png, image/jpeg, image/webp, image/gif) and encoding (base64). After the comma is the actual Base64-encoded data.

Base64 encoding: converts 3 bytes of binary data into 4 characters from a 64-character alphabet (A-Z, a-z, 0-9, +, /). Increases size by approximately 4/3 (about 33% overhead). The result is safe to include in text contexts (HTML, CSS, JSON) where raw binary would be invalid.

Conversion process:
1. Read image as binary bytes
2. Base64-encode the bytes
3. Prepend the data: prefix with MIME type

Size implications:
- 10 KB PNG becomes ~13.3 KB as base64
- 100 KB JPEG becomes ~133 KB as base64
- 1 MB image becomes ~1.33 MB as base64

For large images, this overhead adds up. Browsers cache external images but cache inline data URIs per HTML document — so they don\u2019t share across pages.

Use cases where data URIs help:
- Tiny icons where HTTP request overhead exceeds size benefit
- Single-file HTML for portability (documentation, reports)
- CSS backgrounds for uncommon images where file management overhead isn\u2019t worth it
- JSON-embedded images for APIs that transmit images as data

Use cases where data URIs hurt:
- Large images (HTTP caching wins)
- Images used across many pages (repeated inline data)
- Images that may be updated (hard to update inline)
- Any image where CDN caching would be beneficial

MIME types supported:
- image/png: lossless, transparent
- image/jpeg: lossy, smaller
- image/webp: modern, best compression
- image/gif: animated or legacy
- image/svg+xml: vector (often more efficient NOT base64 — use SVG text directly)

Browser support: data URIs work in all modern browsers for img src and CSS url(). Older IE had size limits; modern browsers handle data URIs of any reasonable size.

Conversion back: Base64 to image is straightforward — decode Base64, get bytes, display as image.

Performance: base64 encoding is fast; even multi-MB images encode in milliseconds.

Common problems and solutions

Size overhead

Base64 is ~33% larger than binary. For large images, inline data URIs increase total page weight significantly. Only use for small images or when inline is specifically needed.

No caching

External images are cached by browsers across page loads. Data URIs are part of the HTML and are re-downloaded whenever the HTML is requested. Not caching-friendly.

Hard to update

Changing an inline image means updating every HTML file containing it. External files update in one place and cascade automatically.

CSS parse performance

Large data URIs in CSS slow parsing. For backgrounds used heavily, consider SVG alternatives or separate image files.

HTTP vs HTTPS

Data URIs don’t have protocol concerns — they’re inline. But the HTML containing them is still subject to HTTP/HTTPS rules.

Base64 inside JSON

If embedding in JSON, ensure proper string escaping. Base64 has no special characters needing escape, so it’s usually safe.

Email client compatibility

Most modern email clients support data URIs for images. Gmail and Outlook are fine; some older webmail has limits on size or format.

Image to Base64 — comparisons and alternatives

Compared to command-line base64 encoding, this tool has a browser UI with preview and copy-ready outputs. CLI is better for scripting; this tool for interactive use.

Compared to online base64 encoders that handle arbitrary data, this tool is optimized for images with image-specific MIME types and preview. General base64 encoders work but don\u2019t provide image-specific features.

Compared to build-tool integration (webpack url-loader, base64-loader), this tool is for ad-hoc conversion. Build tools automate; this tool is for one-off embedding.

Frequently asked questions about the Image to Base64

What is a data URI?

A URL format (data:<mime>;<encoding>,<data>) that embeds data directly in the URL itself instead of pointing to an external resource. For images, data:image/png;base64,<base64 data> puts the entire image inline.

When should I use base64 images?

For small images (under 5-10 KB) used once or twice, or when you need a self-contained file (email, PDF, single-file HTML). For larger images or images used across many pages, external files with HTTP caching are more efficient.

How big is base64 vs the original?

Base64 is about 33% larger than the binary original. A 10 KB image becomes ~13.3 KB base64. A 1 MB image becomes ~1.33 MB. This overhead adds up for large images.

Can I use data URIs in CSS?

Yes. background-image: url(data:image/png;base64,...). Works in all modern browsers. Useful for small background icons where you don’t want a separate HTTP request.

Do browsers cache data URIs?

Data URIs are cached as part of the HTML or CSS that contains them. They’re not cached separately across pages. For images used across many pages, external files with proper caching headers are more efficient.

What MIME types does the tool support?

Auto-detected based on file extension: image/png, image/jpeg, image/webp, image/gif, image/svg+xml, image/bmp. The correct MIME type is essential for browsers to render the image correctly.

Is my image private?

Yes. All encoding runs in your browser. The image data never leaves your machine.

Can I decode base64 back to an image?

Yes. The preview feature shows the image rendered from the base64 data. To save it as a file, right-click the preview and Save Image As.

Additional resources

Advertisement

Related tools

All Image Tools

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →