← All Articles

Complete Guide to Data URIs: Embedding Resources in HTML

March 2026 · 7 min read

Reducing HTTP requests is a key strategy in web performance optimization. Data URIs (also called Data URLs) let you embed small resources directly into HTML or CSS, eliminating extra server requests. This guide covers everything about Data URI syntax, use cases, and best practices.

What is a Data URI?

A Data URI is a URI scheme defined by RFC 2397 that allows data to be included inline within a URL rather than pointing to an external resource. The syntax is:

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

Common Use Cases

1. Embedding Small Images

The most common use is embedding small icons directly in HTML <img> tags or CSS background-image. This is especially effective for images under 2-4KB.

2. CSS Background Images

Using Data URIs in CSS reduces additional image requests during stylesheet loading. They offer a simpler maintenance alternative to CSS sprites.

3. Font Embedding

In some cases, small font files can be embedded in CSS to avoid extra font loading requests.

4. Inline SVG

SVG images are particularly well-suited for Data URIs since SVG is already a text format and can be embedded without Base64 encoding.

Performance Considerations

ProsCons
Fewer HTTP requestsIncreased HTML/CSS file size
No DNS lookup latencyCannot be independently cached
Reduced server loadBase64 adds ~33% overhead
No CORS issuesNot suitable for large resources

Best Practice: According to HTTP Archive research, Data URIs are best suited for resources under 2KB. Beyond that, the Base64 overhead and inability to cache outweigh the benefit of fewer HTTP requests.

When NOT to Use Data URIs

Generate Data URIs Quickly

Use our Base64 tool to quickly convert files to Data URI format:

Try the Base64 Encoder/Decoder →

Conclusion

Data URIs are powerful but require careful use. When applied in the right scenarios, they effectively boost web performance. But overuse can be counterproductive. Knowing when to use them and when not to is the key.

References

  1. Masinter, L. "The 'data' URL scheme." IETF RFC 2397, 1998. https://datatracker.ietf.org/doc/html/rfc2397
  2. Mozilla Developer Network. "Data URLs." MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
  3. HTTP Archive. "State of the Web." HTTP Archive Reports. https://httparchive.org/reports