Technology - Embed Images Data

Image Data URIs: How to Embed Images in HTML Without Hosting Them Anywhere

Data URIs — the trick that lets you put an image directly inside your HTML code, with no upload, no external link, and no hosting service required

A
ADMIN
Technical content team
Published
Updated
2 min read
Image Data URIs: How to Embed Images in HTML Without Hosting Them Anywhere
Featured image for Image Data URIs: How to Embed Images in HTML Without Hosting Them Anywhere
Table of contents
Data URIs: How to Embed Images in HTML Without Hosting Them Anywhere

Data URIs: How to Embed Images in HTML Without Hosting Them Anywhere

A plain-English guide to Data URIs — the trick that lets you put an image directly inside your HTML code, with no upload, no external link, and no hosting service required.

Every time you use an <img> tag, you're used to typing a link — either a path to a local file or a URL pointing somewhere on the internet. But there's a third option most people never touch: you can skip the link entirely and put the actual image data right inside the tag itself. That's what a Data URI does, and once you understand it, it solves a very specific, very annoying problem — needing an image to work without having anywhere to store it.

Diagram comparing traditional image hosting with Data URI embedding
Traditional hosting sends a separate network request to a server for every image. A Data URI skips that request entirely because the image is already embedded inside the HTML itself.

What a Data URI Actually Is

Strip away the jargon and it's simple: a Data URI takes the raw bytes of a file and turns them into a long text string, then hands that string to the browser instead of a link. The browser reads the string, decodes it, and renders it exactly like it would render an image from any normal URL. As far as the browser is concerned, there's no difference — it just sees pixels either way.

An SVG version looks something like this:

<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0i..." alt="An embedded image" />

Everything after base64, is the image itself, encoded as text. There's no separate file sitting anywhere. The image and the HTML are the same document.

Why This Is Actually Useful

The obvious question is: why not just upload the image somewhere and link to it, like normal? Most of the time, that's still the better choice. But Data URIs earn their place in a few specific situations:

  • You genuinely have nowhere to host it. No server, no bucket, no image CDN set up yet — but you still need the image to show up right now.
  • You're sharing a single self-contained file. A one-off HTML report, an email template, or a small tool someone can open by double-clicking, with zero external dependencies.
  • You want to avoid an extra network request. A tiny icon or logo that's small enough not to bloat your page, but important enough that you don't want it to flicker in a moment late.
  • You're building something offline-first. If the HTML file needs to work without internet access, an external image link is useless anyway.

Where It Falls Apart

Data URIs aren't a free lunch, and it's worth being honest about the trade-offs before reaching for one every time:

  • File size grows. Encoding an image as text makes it roughly a third larger than the original file. Fine for a small icon, painful for a large photo.
  • No caching. A normal image URL gets cached by the browser once and reused everywhere. A Data URI is baked into the HTML, so it gets downloaded again every single time that HTML loads.
  • Harder to maintain. Try editing a page that has a giant block of encoded text sitting in the middle of it. It's unreadable, and updating the image means regenerating the whole string from scratch.
  • Not meant for big pages. Once you're embedding several images this way, your HTML file turns into something closer to a binary blob than actual markup.

The Honest Rule of Thumb

Use a Data URI when the image is small, when it needs to travel with the HTML as one self-contained piece, or when setting up real hosting simply isn't worth it for something this minor. For anything bigger — a full gallery, a hero banner, product photos, anything a real website depends on — go back to proper hosting and a normal link. It caches better, it keeps your code readable, and it scales without turning your HTML into a wall of encoded text.

It's not a replacement for hosting. It's a shortcut for the moments when hosting isn't the point.

Continue reading

Related articles