data URI scheme

This is an old revision of this page, as edited by Warnet (talk | contribs) at 19:14, 17 October 2005. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


data: URL is a kind of URL that allows inclusion of small data items as "immediate" data, as if it had been included externally. The URLs allow content creators to embed small files inline HTML documents, without complicated, document level formating, like using MIME and cid: or mid:. It is an IETF standard (RFC 2397).

It is currently supported by Safari, Konqueror, Opera, Internet Explorer, and Mozilla Application Suite (and its derivatives).

Format

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

The <mediatype> is an internet media type specification (with optional parameters.) The appearance of ";base64" means that the data is encoded as base64. Without ";base64", the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range. If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a shorthand, "text/plain" can be omitted but the charset parameter supplied.

The "data" URL scheme has no relative URL forms.

Example

An XHTML fragment embedding a small image (newlines are added for better illustration):

<img
src="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH
hhx4dbgYKAAA7"
alt="Larry" />

A compatible browser should display this image:

File:DataUrlLarry.gif

Note that as an URL, the data: URL should be formattable with whitespaces, but there are practical issues with how that relates to base64 encoding [1]. Authors should ignore using whitespaces for base64 encoded data: URLs.

Limitations

While a URL should be essentially unlimited in length, some web browsers do not support this. For example, URLs in Opera are limited to around 4100 characters. Authors should restrict the use of data: URLs to small files only.

See also