Skip to content

Image to Base64

Convert an image into a Base64 data URL for inline embedding.

Updated · Examples checked by automated tests

LOCAL WORKSPACENO UPLOAD REQUIRED

Drop an image to encode

The file is read locally and never uploaded

About Image to Base64

A data URL embeds a file directly in your markup or stylesheet, removing a round trip to the server. For small, always-needed images that can measurably improve first render.

This tool reads your file locally and produces the complete data URL along with copy-ready HTML, CSS and Markdown snippets.

How Image to Base64 works in your browser

The file is read locally and encoded as a data URL: the MIME type followed by the Base64 representation of its bytes. Base64 uses four characters for every three bytes, so the output is roughly a third larger than the file.

Alongside the raw data URL, the tool gives ready-made snippets for an img tag, a CSS background and Markdown.

When to use it

  • Inlining a small icon in CSS to save a network request.
  • Embedding an image in a single-file HTML document or email template.
  • Putting an image into a JSON payload for an API test.

Worked examples

Inline a tiny icon in HTML

Settings: Default

Input

dot.png, 68 bytes (a 1 × 1 px PNG)

Expected output

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="dot.png" />
Encoded size: 114 characters (+68%)

Base64 needs four characters for every three bytes, plus the data: prefix, so even a tiny file grows. The size line shows the overhead.

Use the same image as a CSS background

Settings: Default

Input

dot.png, 68 bytes (a 1 × 1 px PNG)

Expected output

background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');
Encoded size: 114 characters (+68%)

Inlining saves a network request, which helps only for very small images. Large inlined images block rendering and cannot be cached separately.

Limits and checks before you use the result

  • Keep inlined images to a few kilobytes; the tool flags files over 10 KB.
  • A data URL is about a third larger than the file it encodes.
  • Inlined images are re-downloaded with every page or stylesheet that contains them.

Frequently asked questions

When should I inline an image?

For very small assets - icons, spacers, tiny logos - inlining saves a network request. Above a few kilobytes it usually hurts more than it helps.

Why is the output larger than the file?

Base64 encoding adds about a third to the byte count because it represents three bytes with four characters.

Can I use this in CSS?

Yes. The tool gives you ready-made snippets for an img tag, a CSS background and a bare data URL.

Related tools