Fact-checked by Grok 2 weeks ago

data URI scheme

The data URI scheme is a (URI) scheme that allows small data items, such as images or text, to be embedded directly inline within documents like web pages, eliminating the need to reference external files. The concept was first proposed in August 1995 and has been used in formats like and prior to its formal definition in RFC 2397, published in August 1998 by the (IETF). It provides a standardized method for including media-type data as "immediate" addressing, treating the embedded content as if it were retrieved from an external resource.

Introduction

Definition and Purpose

The is a (URI) scheme that allows the inclusion of small data items inline within documents, as if referencing external resources, using the prefix "data:" followed by an optional , encoding details, and the data payload itself. This approach treats the embedded data as an immediate, self-contained resource rather than a pointer to a separate file or server location. The core purpose of the data URI scheme is to enable the direct embedding of content like images, styles, or scripts into web documents, which reduces the number of HTTP requests and associated overhead, thereby enhancing page load performance and bandwidth efficiency. It also supports offline access by making resources self-contained within the document, eliminating dependencies on external servers, and simplifies the creation and distribution of portable, standalone files such as emails or reports with inline assets. In contrast to schemes like "http:", which retrieve data from remote locations, data URIs encapsulate the content directly, making them ideal for compact payloads such as icons, favicons, or brief text snippets in web pages to avoid unnecessary network round-trips. Common use cases include inlining small graphics in user interfaces to streamline rendering without fetching separate files. Originally outlined in RFC 2397 with an emphasis on embedding simple text data under media types like text/plain, the scheme has expanded in scope to handle diverse formats and now plays a key role in contemporary , including responsive designs that optimize asset delivery and single-page applications that prioritize minimal external dependencies.

History

The data URI scheme originated from the need to embed small media resources directly within documents, avoiding the requirement for external retrieval, which was particularly relevant for applications like email attachments and early where network dependencies could hinder performance or accessibility. In August 1998, Masinter, a researcher at PARC, proposed the scheme in RFC 2397 as an extension to the generic syntax outlined in RFC 2396, defining a method to include inline data with optional media types and encoding for binary content. Early browser implementations emerged in the early 2000s, for example in Opera 7.2 in 2003, with support in starting from in October 2006, enabling embedding images and other small files in . Support remained limited in until version 8 in 2009, which introduced partial compatibility restricted to certain types like images, marking a key step toward broader adoption despite size limitations of 32 KB. Subsequent milestones included formal recognition in the specification starting from its 2008 drafts, where data URIs were validated as permissible values for attributes such as src in <img> elements and href in <a> tags, facilitating their use in structured web documents. In 2014, RFC 7111 extended URI fragment identifier semantics, though primarily for text/csv media types, indirectly supporting more precise referencing within embedded data payloads; however, no fundamental revisions to the core data scheme have occurred since RFC 2397. Post-2014, usage has grown alongside advancements in CSS3 for background images and 6 features like dynamic URL construction, enhancing integration in modern without altering the scheme's foundational design.

Syntax

General Format

The data URI scheme follows a standardized structure defined as data:[<media type>][;parameters],[<data>], where the prefix "data:" identifies the scheme, the media type is optional and specifies the content type (defaulting to text/plain;charset=US-ASCII if omitted), parameters are optional key-value pairs separated by semicolons (such as ;charset=[utf-8](/page/UTF-8) or ;base64), and the comma separates the header from the data payload. This format enables the inline embedding of small data items directly within URIs, treating them as if retrieved from an external resource. Breaking down the components, the scheme begins with the fixed prefix data:, followed by an optional media type in the form of a type (e.g., image/png for PNG images or text/html for HTML content). Semicolon-separated parameters may follow, drawn from parameter conventions, to specify attributes like character encoding (;charset=ISO-8859-1) or indicating base64 encoding (;base64) for . The comma then delimits the header from the <data> portion, which consists of the raw or encoded payload using only URL-safe characters or percent-escaped octets as needed. Parsing adheres to URI rules, restricting the entire string to URL-safe characters (alphanumeric, certain punctuation, and percent-encoded sequences for unsafe octets); spaces and other special characters must be percent-encoded. Length limits vary by implementation, with modern browsers such as Chromium-based ones and Firefox typically supporting up to 512 MB, while Safari allows up to 2 GB, though practical constraints like memory usage apply. For clarity, the format can be expressed in a non-formal Augmented Backus-Naur Form (ABNF)-like as follows:
dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype := [ type "/" subtype ] *( ";" parameter )
data      := *urlchar
parameter := attribute "=" value
Here, urlchar refers to safe URI characters per RFC 2396, parameters follow RFC 2045 conventions (URL-escaped where necessary).

Media Types and Parameters

The media type in a data URI specifies the format and encoding of the embedded data, adhering to the Internet media type standards defined in RFC 2045. It is an optional component placed immediately after the "data:" scheme, in the form data:<mediatype>, and follows the general structure of type/subtype (e.g., text/plain, image/png, or application/json), optionally followed by parameters. These media types must be registered with the to ensure interoperability across systems and applications. If no media type is specified, the default is text/plain;charset=US-ASCII, assuming content encoded in US-ASCII. Parameters provide additional metadata about the data and are appended to the media type using semicolons (e.g., data:text/plain;charset=utf-8). The most common parameter is ;charset=<encoding>, which declares the for text-based media types, such as utf-8 or iso-8859-7, overriding the default US-ASCII when present. Another key parameter is the ;base64 flag, which indicates that the data portion following the comma is encoded in rather than URL-safe ASCII or percent-encoded characters. Other parameters, such as boundary for multipart data, may be included but are rarely used in practice due to the inline nature of data URIs. Parameter values must be URL-escaped if they contain special characters. Media types and their subtypes are case-insensitive, conventionally written in lowercase for consistency (e.g., Text/Plain is treated as text/plain), while parameter names like charset are also case-insensitive, though their values may be case-sensitive depending on the encoding standard. For validation, unregistered or malformed media types do not trigger explicit errors in most user agents; instead, browsers may ignore invalid parameters, fall back to a default handling (such as treating the content as ), or fail to render the data appropriately. A notable limitation is that data URIs do not support query strings or fragments, as their syntax lacks provisions for the "?" or "#" components found in other URI schemes, preventing the passage of additional parameters beyond the media type and its attributes.

Data Encoding

The data payload in a data URI is encoded to ensure compatibility with URI syntax, which requires representing arbitrary octets using only safe characters. By default, without the ;base64 parameter, the data is encoded using percent-encoding as defined in RFC 3986. This method represents each octet as either its corresponding ASCII character if it is unreserved (such as alphanumeric characters, , , , or ) or as a followed by two digits for octets outside this range, including reserved characters when used literally. For example, a space character (octet 0x20) is encoded as %20. For binary or non-text data, the ;base64 parameter specifies encoding, which transforms the octet stream into an ASCII-compatible string using the Base64 alphabet. This encoding, standardized in RFC 4648, processes input in groups of three 8-bit octets (24 bits total), dividing each group into four 6-bit values. Each 6-bit value serves as an index into the 64-character alphabet consisting of A–Z (0–25), a–z (26–51), 0–9 (52–61), plus sign (62), and forward slash (63). If the input length is not a multiple of three, padding is added with one or two equals signs (=) to complete the final quartet: one = for two remaining octets and two = for one remaining octet. The process can be summarized as: for input bytes b_1, b_2, b_3, form a 24-bit value (b_1 \times 2^{16}) + (b_2 \times 2^8) + b_3, then extract four 6-bit indices i_1 = \lfloor v / 2^{18} \rfloor \mod 2^6, i_2 = \lfloor v / 2^{12} \rfloor \mod 2^6, i_3 = \lfloor v / 2^6 \rfloor \mod 2^6, i_4 = v \mod 2^6, and map each i_k to the corresponding alphabet character. The choice of encoding follows specific rules to balance readability, safety, and efficiency. is used for text data to preserve human readability where possible, as it minimally alters safe characters, but it becomes inefficient for binary data due to the need to encode nearly every octet. is required for non-text MIME types (such as image/png or application/octet-stream) to avoid corruption from percent-encoding's text assumptions, and it is optional but recommended for any data containing non-safe octets. No other encodings, such as from , are supported in data URIs. Base64 introduces a size overhead, as it converts three octets into four characters, yielding an expansion ratio of approximately $4/3 (or about 33% larger than the original data), plus minimal padding for incomplete groups. This trade-off enables safe embedding of binary payloads in text-based contexts like HTML.

Usage

In HTML

Data URIs enable the embedding of small resources directly within HTML documents, allowing content to be included inline without requiring external fetches. This is particularly useful for incorporating images, text, or other media types into markup, reducing the number of HTTP requests and improving page load performance for minor assets. The scheme integrates seamlessly with HTML content attributes that accept URLs, as defined in the HTML Living Standard. In , data URIs are commonly used in the src attribute of the <img> element to display inline images, such as icons or small graphics, by encoding the image data in base64 format following the general syntax data:image/<type>;base64,<encoded-data>. For instance, this approach allows developers to embed a simple icon directly in the markup without linking to a separate file. Similarly, the <a> element can utilize data URIs in its href attribute to provide downloadable text or data files, enabling users to access generated content like exports or snippets without server involvement. The <object> element supports data URIs in its data attribute for embedding various resource types, such as PDFs or , treating the inline data as the content to render within the object. Supported HTML elements for data URIs include <img> for images, <input type="image"> where the src attribute can reference an inline image for form submission coordinates, <link> for occasional stylesheet inclusion (though uncommon due to size constraints), and <script> for inline code, with the caveat that some implementations may impose restrictions on execution from data schemes. Under specifications, data URIs receive full support in content attributes across these elements, functioning as valid URLs without inherent size limits beyond browser-imposed defaults on attribute lengths or overall document parsing. Additionally, when used in <iframe src="data:...">, data URIs interact with the sandbox attribute to control embedded content behavior, ensuring isolated rendering. Best practices recommend employing data URIs in for small resources, such as icons or thumbnails typically under 10 , to avoid inflating the document's size and potentially impacting efficiency or usage. Large should be avoided to prevent DOM bloat, favoring external references for substantial files to maintain optimal and .

In CSS

Data URIs can be embedded directly within CSS declarations to reference inline resources, such as images or fonts, eliminating the need for separate HTTP requests. This approach is particularly useful for small assets in stylesheets, where the url() accepts a data URI as its value. The syntax follows the general data URI format, often using encoding for to ensure compatibility across browsers. Several CSS properties support data URIs to incorporate inline . The background-image property allows embedding , such as or files, directly into styles for elements like buttons or divs; for instance, background-image: url("data:image/svg+xml;base64,..."); renders an inline SVG without an external file. Similarly, the content property in pseudo-elements like ::before or ::after can display data URIs for generated , such as content: url("data:image/gif;base64,..."); to insert a small . The list-style-image property uses data URIs to customize bullet points in unordered lists, enabling compact, self-contained styling for navigation menus or itemized . In CSS3 and later specifications, data URIs extend to advanced features like custom fonts and cursors. The @font-face at-rule supports data URIs in the src descriptor for embedding fonts, such as WOFF files, allowing src: url("data:font/woff;base64,...") format('woff'); to load typography without server fetches, though this is optimized for small font subsets due to size constraints. The cursor property also accepts data URIs for custom mouse pointers, as in cursor: url("data:image/png;base64,..."), auto;, providing fallback to default cursors while embedding pointer graphics inline. These capabilities are defined in the CSS Fonts and CSS Basic User Interface modules, respectively. Data URIs in CSS have specific limitations to consider for robust implementation. Data URIs are static and cannot be loaded dynamically; however, they can be used in and animations where the function is supported, though external resources may be preferred for conditional or dynamic loading. Additionally, if the data URI string contains special characters like parentheses or quotes, it must be enclosed in quotes to avoid errors in the CSS . Browser-imposed length limits apply, with older versions like IE8 capping at 32KB, though modern engines handle up to several megabytes. Practical examples highlight data URIs' role in efficient CSS. Embedding an icon as a background-image supports responsive without rasterization issues, as shown in div.icon { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2L2 7v10c0 5.55 3.84 10 9 10s9-4.45 9-10V7l-10-5z'/%3E%3C/svg%3E"); background-size: contain; }, ideal for in fluid layouts. Inline CSS snippets via data:text/css are rare but possible for embedding simple styles, such as gradients in isolated rules, though native CSS gradient functions are typically preferred for performance.

In JavaScript

In , data URIs can be generated dynamically to embed small files or directly into code, avoiding external resource fetches. The btoa() function encodes as a string, which forms the payload of a data URI when prefixed with the appropriate scheme and , such as data:text/plain;base64, followed by the encoded string. For images rendered on a , the toDataURL() of the HTMLCanvasElement directly returns a data URI representing the canvas content in a specified format, like , enabling programmatic export without server involvement. These data URIs are commonly used in the (DOM) to set attributes dynamically, such as assigning one to the src property of an HTMLImageElement created via document.createElement('img'), which loads the embedded data as an image without network requests. Similarly, data URIs can be applied to other elements like <video> or <audio> for inline media playback. However, support for data URIs in XMLHttpRequest is limited across browsers due to security restrictions on non-HTTP schemes, preventing their use as request URLs in most cases, though they may work for certain asynchronous operations in specific implementations. In environments, data URIs are constructed server-side using the Buffer class, where binary data is converted to via toString('base64') and assembled into the URI format, often for generating email attachments, responses, or dynamic content in templates. This approach leverages 's built-in encoding utilities without additional libraries. For advanced handling, the FileReader converts Blob or File objects to data URIs asynchronously using the readAsDataURL() , which is useful for processing user-uploaded files or fetched blobs before embedding them in the DOM. In Web Workers, data URIs enable offline processing by allowing worker scripts to be instantiated directly from inline data via the Worker() constructor, or by passing embedded resources between threads for computation without main-thread blocking.

In SVG and Other Formats

Data URIs enable the embedding of raster images directly within documents using the <image> element's href attribute (formerly xlink:href in SVG 1.1), allowing self-contained without external dependencies. For instance, an can reference a base64-encoded as href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD...", which renders the image inline while preserving scalability. This approach is particularly useful for icons or diagrams, as it complies with SVG 2 specifications for embedded content and supports secure modes where external resources are restricted. SVG documents can also incorporate external stylesheets via data URIs in <style> elements, such as <style>@import url("data:text/css;charset=utf-8,body { color: red; }");</style>, facilitating fully encapsulated styling without separate files. Entire SVG files can be self-contained by encoding the full document as a data URI, e.g., data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><circle cx="50" cy="50" r="40" fill="red"/></svg>, which is ideal for inline usage in larger web contexts. These methods adhere to the data URI scheme defined in RFC 2397, ensuring compatibility across SVG implementations. For interoperability, data URIs in require compliance with SVG 1.1 or later, where URI references in elements like <image> and <use> support the scheme for internal resources. Tools like facilitate this by embedding raster images as data URIs during SVG export via Extensions > Images > Embed Images, producing optimized, portable files suitable for web or print workflows. Beyond , data URIs integrate into XML and for embedding structured content, such as data:application/xml,<root><element>content</element></root> in attributes or entity references, enabling inline XML fragments without external loading. In email , data URIs allow -encoded images within multipart/related messages, e.g., <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==">, though rendering varies by client like due to security filters. JSON APIs commonly embed base64 payloads as data URIs for assets like images, serializing them as strings within objects, e.g., {"image": "data:image/png;base64,iVBORw0KG..."}, to transmit compact, self-contained responses over HTTP. In PDF generation tools such as jsPDF, data URIs convert uploaded or fetched images to base64 for direct addition to documents via doc.addImage(dataURI, 'PNG', x, y, width, height), streamlining PDF creation without file I/O. Web Components leverage data URIs within shadow DOM to encapsulate assets, such as defining an inline image in a custom element's : const template = document.createElement('template'); template.innerHTML = '<img src="data:image/svg+xml,<svg>...</svg>">';, ensuring isolated, portable styles and media that avoid global conflicts.

Advantages and Limitations

Benefits

One key benefit of the data URI scheme is the reduction in HTTP requests, as it allows small pieces of data, such as images or stylesheets, to be embedded directly within , CSS, or other documents, eliminating the need for separate network fetches. This is particularly advantageous for micro-assets like favicons or icons, where the overhead of an additional request can introduce noticeable on slow or congested networks. The scheme enhances offline capability by enabling fully self-contained web pages that do not rely on external resources, making it suitable for scenarios where network access may be unavailable or restricted, such as emails. In emails, inline data URIs can prevent broken images due to blocked , though support varies across clients, with many like not rendering them reliably for security reasons. Data URIs contribute to savings, especially in or low-data scenarios, by avoiding the transmission of HTTP headers and round-trip times associated with separate requests. The inline approach can minimize overall data transfer for small payloads, reducing costs and improving load times on metered connections. Regarding caching and portability, data URIs simplify deployment for static sites and content delivery networks (CDNs) by bundling into the primary , which is then cached holistically without managing separate asset caches or external dependencies. This self-contained nature enhances portability, as the entire page can be distributed or archived as a single file, independent of server availability or link breakage.

Drawbacks and Best Practices

One significant limitation of data URIs is the increased size due to encoding overhead, particularly when using , which expands by approximately 33% compared to the original format. This bloat, combined with browser-imposed size limits—such as 32 KB in older versions of and up to 512 MB in modern Chromium-based browsers and —can lead to parsing failures or degraded performance for larger payloads, ultimately slowing page load times. Data URIs also lack independent caching mechanisms, unlike HTTP resources, which means they cannot leverage caches, validation, or 304 not-modified responses; instead, they are re-parsed with every load of the containing , increasing CPU usage and bandwidth consumption on repeated visits. From a perspective, embedding data directly into or CSS files complicates updates, as changes to the inline content require modifying and redeploying the entire , which bloats file sizes and disrupts efficient caching of the stylesheet or markup itself. To mitigate these issues, developers should limit data URIs to small assets under 1 KB, where the encoding overhead is outweighed by reduced HTTP requests, and consider alternatives like HTTP/2 multiplexing for larger resources to minimize connection latency. Always test implementations across browsers to account for varying limits and behaviors, and for vector graphics, prioritize SVG data URIs over raster formats to avoid unnecessary compression artifacts and size inflation.

Security Considerations

Malware and Phishing Risks

Data URIs pose significant risks for distribution by allowing attackers to embed executable scripts or payloads directly within web content, bypassing traditional network-based detection mechanisms. For instance, (XSS) attacks can leverage data URIs to inject malicious , such as through a <script src="data:text/javascript;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4="></script> tag, where the -encoded payload executes arbitrary code in the victim's browser context. Similarly, obfuscated encoding can hide viruses or exploits within seemingly innocuous data URIs, like data:image/png;base64,... that decodes to executable content rather than a valid , enabling drive-by downloads without user interaction. Phishing tactics often exploit data URIs to forge deceptive login pages or mimic trusted sites, embedding entire forms encoded in to harvest credentials without relying on external servers. Attackers may nest data URIs within , as seen in obfuscated payloads that load iframes mimicking services like sign-in, tricking users into entering sensitive information. In email campaigns, data URIs in attachments or links can bypass content filters by avoiding remote resolution, with the malicious content rendered inline upon opening. Notable attack examples include XSS via URI placeholders in HTML attributes, where a malicious link like <a href="data:text/html;base64,PGJvZHk+PGZvcm0gYWN0aW9uPSJodHRwOi8vYXR0YWNrZXIuY29tIj48aW5wdXQgdHlwZT0icGFzc3dvcmQiPjwvZm9ybT48L2JvZHk+" impersonates a legitimate site to steal data. Drive-by downloads have been facilitated by manipulated image sources using data URIs to load exploitable payloads, potentially installing malware silently. Historical incidents from the 2010s, such as 2014 phishing kits targeting Yahoo and Gmail via base64-encoded data URIs in compromised redirects, demonstrated how these schemes enable credential theft by posting data to attacker-controlled scripts. Detection challenges arise from the inline nature of data URIs, which evade URL scanners focused on external domains, requiring instead deep content inspection and base64 decoding that many tools overlook. Reliance on content-type validation can fail if attackers mismatch types, like claiming text/html for executable code, complicating real-time analysis. Additionally, browser-specific behaviors, such as truncating long data URIs or hiding prefixes in address bars, aid impersonation in phishing, as observed in vulnerabilities allowing origin spoofing. While JavaScript usage amplifies these exploits by enabling dynamic payload execution, browser security measures like same-origin policy enforcement provide partial defenses against such threats.

Browser Security Measures

Browsers enforce strict content-type validation for data URIs to prevent the execution of malicious payloads, particularly those with executable MIME types like text/html or application/javascript. For example, Google Chrome blocks data URIs with javascript MIME types in top-level contexts and certain non-sandboxed environments to mitigate cross-site scripting risks. Similarly, when loading data URIs in iframes, browsers apply the HTML5 sandbox attribute, which treats the content as originating from a unique origin and disables features like script execution unless explicitly permitted via tokens such as sandbox="allow-scripts". Navigation restrictions further limit the potential for abuse, with major browsers prohibiting top-level navigations to data URIs to thwart phishing attempts that could impersonate legitimate sites. Firefox has blocked such top-level navigations since version 59, preventing web pages from redirecting the main window to a data URI and thereby protecting user credentials. Safari and Chrome follow analogous policies, deprecating top-frame loads via mechanisms like anchor tags or window.location assignments to data URLs. Additionally, Content Security Policy (CSP) directives enable site administrators to block the data: scheme entirely for resources like scripts or stylesheets, for instance by omitting data: from script-src allowlists, thereby enforcing granular control over inline data usage. To safeguard against parsing vulnerabilities, browsers implement size limits on data URIs during base64 decoding and content extraction, capping payloads to avoid memory exhaustion or denial-of-service conditions; Chromium and Firefox enforce a 512 MB limit, while Safari allows up to 2 GB but with equivalent validation. Malformed URIs trigger immediate error handling, rejecting invalid encodings or syntax without processing, as part of standard URI resolution protocols. Browser extensions enhance these measures; for instance, uBlock Origin supports static filters that can block or redirect requests matching data URI patterns, allowing users to customize protections against suspicious inline content.

Standards and Implementation

Formal Specification

The data URI scheme is formally defined in RFC 2397, titled "The 'data' URL Scheme," published by the Internet Engineering Task Force (IETF) in August 1998. This document introduces the scheme to embed small data items directly within Uniform Resource Identifiers (URIs), treating them as if retrieved from an external source, without requiring a separate network request. The core syntax specified is dataurl := "data:" [ mediatype ] [ ";base64" ] "," data, where mediatype follows the structure from RFC 2045 for MIME types (optionally including parameters like charset), and data consists of URL-safe characters or Base64-encoded content if the ;base64 flag is present. If the mediatype is omitted, it defaults to text/plain;charset=US-ASCII. An erratum issued in 2010 clarified that the data component uses the *uric production from URI syntax rather than the undefined urlchar. The specification aligns with broader URI standards, particularly the generic syntax in , which defines components like scheme, path, query, and fragment, though predates it and references earlier URI documents ( and ). Media types within data URIs must conform to 's MIME type rules and are expected to be registered in the IANA Media Types registry to ensure interoperability. Parsing and serialization of data URIs in web contexts are further detailed in the , which provides algorithms for handling the scheme, including percent-encoding rules for the data portion. Although RFC 2397 does not include fragment identifiers (the # component from RFC 3986), later standards extend support for them in data URIs, with interpretation based on the embedded media type. For instance, when the media type is text/plain, fragments enable reference to specific character or line positions as defined in RFC 5147. The WHATWG URL Standard explicitly parses # as delimiting the fragment in data URIs, treating preceding content as the data payload. No official multipart support (e.g., for multiple embedded resources) is defined in the core specification or subsequent errata. Post-1998 updates to the data URI scheme have been limited to errata clarifications, such as handling of parameter quoting and encoding ambiguities, with no new IETF RFCs superseding or obsoleting RFC 2397. The scheme is referenced in web platform standards, including the W3C CSS Images Module Level 3 (published 2023, with earlier drafts from the 2010s), which permits data URIs within url() functions for image sources. Extensions beyond the RFC appear in specifications like the HTML Living Standard, where the CanvasRenderingContext2D.toDataURL() method generates data URIs for canvas content, typically with media types like image/png or image/jpeg.

Browser Compatibility

The data URI scheme enjoys broad support across modern web browsers, with full implementation in major desktop engines since the late 2000s. Chrome has provided full support since version 4 (released in 2010), allowing data URIs for images, CSS resources, and other embeddable content. Firefox introduced full support in version 2 (2006), enabling usage in HTML attributes like <img src> and CSS properties. has supported data URIs fully since version 3.1 (2008), with consistent handling across macOS and environments. offers full support from version 79 (2020), building on ; earlier versions from Edge 12 (2015) provided partial support limited to specific contexts like images. had partial support starting with version 8 (2009), restricted to images and certain CSS uses with a 32 size limit, and full support—including CSS backgrounds—only from IE9 (2011).) On mobile platforms, support mirrors desktop counterparts but with some historical variances in older devices. The Browser has supported data URIs since version 2 (2009), with full functionality in for from version 18 (2012). iOS provides full support from version 3.2 (2009), aligning with desktop capabilities. Older versions of exhibited limitations, such as restricted rendering of complex data URIs until updates around 2013, though modern (post-version 10, 2010) offers full support. Feature variations exist primarily in size limits and specific APIs, though base64 encoding is universally supported across all compliant browsers for efficient data embedding. Current limits include 512 MB in Chromium-based browsers (like Chrome and Edge) and Firefox, and up to 2 GB in Safari/WebKit. The canvas.toDataURL() method, introduced with HTML5 Canvas in the early 2010s, generates data URIs from canvas elements and is fully supported in Chrome 4+, Firefox 2+, Safari 3.1+, and Edge 12+. In progressive web apps (PWAs), data URIs can be used within service workers for offline caching, with support emerging post-2015 in Chrome 40+, Firefox 44+, and Safari 11.1+.
BrowserFull Support VersionNotes
(Desktop/Android)4+ (2010)512 MB limit; full for images, CSS, JS.
Firefox (Desktop/Android)2+ (2006)512 MB limit; early leader in adoption.
Safari (Desktop/)3.1+ (2008)2 GB limit; consistent across Apple platforms.
79+ (2020)Partial 12–18 (2015–2019); Chromium-based.
Internet Explorer9+ (2011)Partial 8 (2009): images/CSS only, 32 KB limit.
(Desktop/Mobile)10+ (2010)Full base64 and embedding support.

References

  1. [1]
    RFC 2397 - The "data" URL scheme - IETF Datatracker
    A new URL scheme, "data", is defined. It allows inclusion of small data items as "immediate" data, as if it had been included externally.
  2. [2]
  3. [3]
    Data URIs | Can I use... Support tables for HTML5, CSS3, etc
    "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.Missing: scheme | Show results with:scheme
  4. [4]
  5. [5]
    URL Standard
    Oct 30, 2025 · The URL Standard defines URLs, domains, IP addresses, the application/x-www-form-urlencoded format, and their API.
  6. [6]
  7. [7]
    Data URIs | CSS-Tricks
    Oct 30, 2024 · ASCII is another, where the code is essentially URL encoded, or UTF-8. Browser Compatibility. Data URI's don't work in IE 5-7, but are supported ...
  8. [8]
    RFC 2397: The "data" URL scheme
    A new URL scheme, "data", is defined. It allows inclusion of small data items as "immediate" data, as if it had been included externally.
  9. [9]
    RFC 7111: URI Fragment Identifiers for the text/csv Media Type
    This memo defines URI fragment identifiers for text/csv MIME entities. These fragment identifiers make it possible to refer to parts of a text/csv MIME entity ...
  10. [10]
  11. [11]
    data: URLs - URIs - MDN Web Docs - Mozilla
    Oct 31, 2025 · Data URLs, URLs prefixed with the data: scheme, allow content creators to embed small files inline in documents. They were formerly known as ...
  12. [12]
  13. [13]
    Media types (MIME types) - HTTP - MDN Web Docs
    Aug 19, 2025 · MIME types are case-insensitive but are traditionally written in lowercase. The parameter values can be case-sensitive. Types. There are two ...
  14. [14]
  15. [15]
  16. [16]
  17. [17]
  18. [18]
  19. [19]
  20. [20]
  21. [21]
  22. [22]
    SVG as an image - MDN Web Docs
    May 13, 2025 · SVG can be used as an image format in HTML, CSS, certain SVG elements, and via the Canvas API. This page lists the features where you can provide SVG as an ...
  23. [23]
  24. [24]
    Window: btoa() method - Web APIs - MDN Web Docs - Mozilla
    Jun 24, 2025 · The btoa() method of the Window interface creates a Base64-encoded ASCII string from a binary string (ie, a string in which each character in the string is ...
  25. [25]
    HTMLCanvasElement: toDataURL() method - Web APIs | MDN
    Sep 11, 2025 · The HTMLCanvasElement.toDataURL() method returns a data URL containing a representation of the image in the format specified by the type parameter.Syntax · Examples
  26. [26]
    HTMLImageElement: src property - Web APIs | MDN
    Apr 10, 2025 · This can be set either within the HTML itself using the src content attribute, or programmatically by setting the element's src property. If ...
  27. [27]
    XMLHttpRequest Standard
    Aug 18, 2025 · The XMLHttpRequest Standard defines an API that provides scripted client functionality for transferring data between a client and a server.
  28. [28]
    Buffer | Node.js v25.1.0 Documentation
    Buffer objects represent a fixed-length sequence of bytes, and are used by many Node.js APIs. The Buffer class is a subclass of JavaScript's <Uint8Array> class.Missing: URI | Show results with:URI
  29. [29]
    FileReader: readAsDataURL() method - Web APIs | MDN
    Sep 18, 2025 · The readAsDataURL() method of the FileReader interface is used to read the contents of the specified Blob or File.Missing: scheme | Show results with:scheme
  30. [30]
    Worker() constructor - Web APIs - MDN Web Docs
    Jun 23, 2025 · The Worker() constructor creates a Worker object that executes the script at the specified URL. This script must obey the same-origin policy.WorkerLocation · Using Web Workers · Worker · Web Workers API
  31. [31]
    Linking — SVG 2 - W3C
    A URL reference to an embedded document specified using the "data" URL scheme [rfc2397]. Data URL references are neither external file references nor same- ...
  32. [32]
    Document Structure – SVG 1.1 (Second Edition) - W3C
    An SVG document fragment consists of any number of SVG elements contained within an 'svg' element. An SVG document fragment can range from an empty fragment.
  33. [33]
    Serialize in JSON a base64 encoded data - Stack Overflow
    May 14, 2016 · I'm writing a script to automate data generation for a demo and I need to serialize in a JSON some data. Part of this data is an image, so I encoded it in base ...How to embed a Base64 encoded PDF data URI into a HTML 5 ...What are the pros and cons of Base64 file upload through JSON, as ...More results from stackoverflow.com
  34. [34]
    Generating PDFs from Web Pages on the Fly with jsPDF - SitePoint
    Feb 16, 2016 · Adding images to your PDF using jsPDF is a straightforward process. First, you need to convert your image into a Data URL. You can use ...<|separator|>
  35. [35]
    Implementing single-file Web Components - CKEditor
    Mar 20, 2020 · Additionally, every component will use Shadow DOM that will store styles and template content. ... This way you get all advantages of Data URIs ...<|separator|>
  36. [36]
    Offline and background operation - Progressive web apps | MDN
    Jun 23, 2025 · Offline operation allows a PWA to provide a good user experience even when the device does not have network connectivity.Offline Operation · Background Fetch · Handling Request Outcomes<|control11|><|separator|>
  37. [37]
    html - Why use data URI scheme? - Stack Overflow
    Jul 25, 2011 · A good use of Data URI is allowing the download of content that have been generated client side, without resorting to a server-side 'proxy'.What are pros and cons of using data URIs in HTML and CSS?What is the purpose of data URIs? - Stack OverflowMore results from stackoverflow.comMissing: benefits | Show results with:benefits
  38. [38]
    Page Speed: Avoid Large Base64 data URLs in HTML and CSS
    Mar 7, 2025 · Base64 is a binary-to-text encoding method that converts binary data into a string using 64 ASCII characters. ... Example of a Base64 image data ...Missing: mandatory | Show results with:mandatory
  39. [39]
    What is the space overhead of Base64 encoding?
    Jan 30, 2019 · Base64 encoding wastes 2 bits per 8 bits, making the file at least 4/3 larger, or 33% more storage than the original.
  40. [40]
    The Dangers of data URIs - Web Performance Calendar
    Dec 22, 2020 · data URIs are opaque, it's hard to tell what resource is being encoded. Often the quickest way to discover what the data URI represents is to ...Missing: scheme | Show results with:scheme
  41. [41]
    How to Know Whether to Use Data URLs - OddPen
    Feb 24, 2024 · Let's repeat this: if the overhead of a request to an external resource exceeds the size of the Base64 extra bloat, you should use a data-url.
  42. [42]
    Reducing HTTP requests with generated data URIs - SitePoint
    Nov 11, 2024 · You can reduce the number of HTTP requests that a page has to make for its images, by pre-processing the source-code and converting them to data URIs.Missing: bandwidth | Show results with:bandwidth
  43. [43]
    Cross Site Scripting (XSS) - OWASP Foundation
    XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user. Flaws ...
  44. [44]
    CAPEC-244: XSS Targeting URI Placeholders (Version 3.9)
    An attack of this type exploits the ability of most browsers to interpret data, javascript or other URI schemes as client-side executable content placeholders.
  45. [45]
    [PDF] Obfuscation Techniques in Phishing Attacks - Threat Insight
    This technique makes use of data URIs to obfuscate the phishing landing page by instructing the browser to load the base64 code as the page content. The browser ...
  46. [46]
    Phishing with data: URIs | Netcraft
    Oct 8, 2014 · These special URIs allow the content of a phishing page to be contained entirely within the URI itself, effectively eliminating the need to host the page on a ...Missing: benefits | Show results with:benefits
  47. [47]
    [PDF] insecure:// Vulnerability Analysis of URI Scheme Handling in ...
    Apr 28, 2022 · Internet that allows abusing data URIs to impersonate origins and protocols, posing a threat in the context of phishing attacks. Finally, we ...Missing: risks | Show results with:risks
  48. [48]
    Intent to Deprecate and Remove: Top-frame navigations to data URLs
    We intend to block web pages from loading data: URLs in the top frame using <A> tags, window.open, window.location and similar mechanisms.
  49. [49]
    Blocking Top-Level Navigations to data URLs for Firefox 59
    Nov 27, 2017 · Firefox 59 will prevent web pages from navigating the top-level window to a data URL and hence will prevent stealing an end user's credentials.Missing: restrictions | Show results with:restrictions
  50. [50]
  51. [51]
  52. [52]
  53. [53]
  54. [54]
    RFC Errata Report » RFC Editor
    "URI"s are first documented in RFC 2396, which was developed at the same time as RFC 2397. At the time the document that became 2397 was approved, " ...
  55. [55]
  56. [56]
    CSS Images Module Level 3 - W3C
    Dec 18, 2023 · The simplest way to indicate an image is to reference an image file by URL. This can be done with the url() notation, defined in [CSS-VALUES-3].Image Values: the <image> type · Gradients · Sizing Images and Objects in...Missing: URI scheme