Image to data URI

Generate a Data URI from an Image

Turn any image into a ready data:image URI you can paste straight into CSS, HTML, or JSON — free and right in your browser.

Drop an image to encode

Drag & drop, paste, or pick a file

PNG · JPG · WebP · GIF · SVG — encoded on your device

Ready data URICSS + HTML snippetsNo sign-up PNG · JPG · WebP · GIF · SVG

What is a data URI?

A data URI is a self-contained string that embeds a whole file inline. For an image it looks like data:image/png;base64,iVBORw0KGgo… — the browser reads the string itself as the image, with no separate request to a server. It's perfect for inlining a small icon into a stylesheet, embedding a logo in an HTML email, or shipping an asset inside a single JSON or config file.

This generator builds the data URI from the exact bytes of your file, so it's a faithful, lossless copy. Alongside the URI you get a copy-ready CSS background-image rule and an <img src> tag, so you can drop it straight into your project.

How to generate a data URI

  1. Open your image. Drag an image onto the tool, choose a file, or paste it from your clipboard.
  2. Choose Data URI (or CSS / HTML). The Data URI tab gives the full data:image string; the CSS and HTML tabs wrap it for you.
  3. Copy and paste. Tap Copy and paste the URI into your CSS, HTML, or JSON — or download it as a .txt file.

Best for small assets

Data URIs shine for small, rarely-changing assets that you want bundled with your code. For large or frequently-cached images, a normal URL is usually faster because the browser can cache the file on its own.

Image to data URI: how it works

A data URI is the full self-contained string a browser can use directly as an image source: the scheme data:, the media type, the ;base64 marker, a comma, and then the Base64 body — no separate file or server request needed.

Data URI shape
data:[<mime-type>];base64,<base64-body> e.g. data:image/svg+xml;base64,PHN2Zy…
Size impact
The Base64 body adds the usual ~33% over the binary file, and the data:<mime>;base64, prefix adds a fixed handful of extra characters on top (typically around 20–30, depending on the media type).

When inlining as Base64 makes sense

  • You want a one-line, paste-anywhere asset for a CSS background-image: url("data:…") rule or an <img src="data:…"> tag.
  • You're embedding an image in something that only carries text — a JSON document, an SVG, an HTML email, or a single-file HTML page.
  • You want to remove a render-blocking request for a tiny, above-the-fold icon so it paints with the first response.

When a normal file or URL is better

  • The asset is big or shared across pages — an external URL lets the browser cache it once instead of re-parsing it everywhere it's inlined.
  • You rely on a Content Security Policy that forbids data: URIs in img-src or style-src, which many strict CSP setups do by default.

Practical tip

For SVG specifically, a percent-encoded (URL-encoded) data URI is often smaller than a Base64 one because SVG is already text; Base64 is the safe, universal choice, but URL-encoding can save bytes when every kilobyte counts.

More Base64 & data URI tools

Frequently asked questions

What's the difference between a data URI and Base64?

Base64 is the encoded text of the file; a data URI is that text plus a data:<mime>;base64, prefix that tells the browser what it is, so it can be used directly as a source.

Can I use the data URI in CSS?

Yes — the CSS tab gives you a ready background-image: url("data:…") rule. Paste it into any stylesheet or inline style.

Does it work with SVG?

Yes. SVG, PNG, JPG, WebP, GIF, BMP, AVIF, and ICO all produce a valid data URI with the right media type.

Where is my image processed?

The encoding and decoding happen in your browser, so the result is created on your own device. How any data associated with the tool is handled is described in our privacy policy.

More image tools