What Is a Data URI?

What Is a Data URI?

You’ve seen a URL that starts with data: — a tiny image encoded as a wall of characters sitting inside an HTML file. That’s a data URI, and it’s the web’s way of shipping a file inside a file.

What it is

A data URI embeds a file’s content directly in a string:

data:image/png;base64,iVBORw0KGgo...

Three parts: the data: scheme, the MIME type, and the content (base64-encoded for binary). Browsers decode it and treat it exactly like a file at a real URL — no network request needed.

Why people use them

  • Zero extra requests: a small icon embedded in HTML loads with the page — no second HTTP round-trip. For tiny assets, that’s a real performance win.
  • Self-contained files: an HTML report with all its images embedded travels as one file — email attachments, exported documents, offline pages.
  • No hosting needed: the file lives in the document, not on a server.

The limits

  • Size tax: base64 inflates files by ~33%. A 1 MB image becomes a 1.33 MB string. Data URIs are for small assets — icons, thumbnails, sprites. Embedding a hero photo is a mistake.
  • No caching separation: an image at a URL is cached independently; an embedded one re-downloads with every HTML change.
  • CSP and tooling: some content security policies and email clients block or strip data URIs entirely.

Creating and reading them

  • Create: use the data URI converter to turn a file into a data URI. For SVG specifically, the SVG data URI converter handles URL-encoding, which SVG-in-CSS often requires instead of base64.
  • Read: paste a data: URL into the converter to extract the original file back out.

The rule of thumb: under ~2 KB and reused on one page, embed it. Anything bigger, host it.