
Have you ever felt the need for holding an embedded image inside an HTML file, without referring to an external image file? Personally I felt like so many occasions, where the need for a completely self contained HTML page, with all its supporting images embedded within that page itself. This may seem pointless in normal situations, but it can prove very useful when we want to make a standalone page, that we can pass on to other people. We give them just one HTML file. They do not even need to unpack anything, they can simply open the file in their browser, and all the images and embedded objects are immediately displayed. They can do this even without an internet connection.
Below you can see two images first one is included in the traditional way by referring to an external file, and the later by using data URI.
Try right-clicking the above images and check the file location in the properties panel. You can see the difference.
With Data URI (Uniform Resource Identifiers) we can easily do this.
Data URI scheme defined in IETF standard RFC 2397, as an URI scheme that allows inclusion of small data items inline, as if they were being referenced to as an external resource. They tend to be far simpler than alternative inclusion methods, such as MIME with cid: or mid: As per the wording in the RFC, data: URIs are in fact URLs, although they do not actually locate anything.
In HTML normally we use an IMG tag like below to refer/link an external image.
1 | <img src="mages/myGravatar.gif" alt="" /> |
While rendering the page, the browser sends separate individual HTTP requests for each external resources used in that page, tying up valuable network resources. Since most of today’s browsers limit about 3 or 4 parallel requests at a time, a page with so many external references can cause the requests to get queued up. This may eventually cause performance degradation.
With data URIs the same IMG tag can be represented like below.
1 2 3 4 5 6 7 8 9 10 11 12 | <img src="data:image/gif;base64,R0lGODlhXgBDAIAAAAAAAP///yH 5BAAAAAAALAAAAABeAEMAAAL/jI+py+0Po5y02ouz3rw3AB6hR3oggKCG WrbaCYenS1vxjaNszSf5D+sJRcDiUFhMxo4lpTPI3Dynu6iNirVesVMthZv1S sAjpziihKTPj+TEyP64v784Y16p2xXwS27P9/ciCLiC03ETULV3iJhYmDLjsNg mCblCFEn5ZnmpqbPk1+lpqNJINPpJijqiGPa5aVcGGxa6islKBnW7YLbGe9fXx 7j1WHoKOMuZqrfaKgUUt5kqiixWpnMcu7xr1QmKTV3cXX0a9OzaaoyGro2 LoSdDngkuLjefMthoeg4Vfb/DVqB23NLtm/FkUih89bZVqhVPmQ9t9VxRJMh OlzlspRkf/ctDxaAxcMc6SkpkT6FGSwKpdfO3EJKlbBUDVyJ8aYuWjx17lyXC 0zPoLFwErrYxQfDj7SM4tQZbI3TqQRliqSK9ajSnCGzkqlk8t+rsM3uke2X08Q wsGflpXTkEM2YkMDePUxYlw5dXmmbwrTati8nNXOAKgW4BC28uHis3RUK kttLx1H/qCt7F+QirYjFrq2sljLSrQ3xgIbr2G1itCAKAAA7" alt="myGravatar.gif" /> |
In CSS.
1 2 3 4 5 6 7 8 9 10 11 12 | background-image: url("data:image/gif;base64,R0lGODlhXgBD AIAAAAAAAP///yH5BAAAAAAALAAAAABeAEMAAALjI+py+0Po5y02ouz3rw3A B6hR3oggKCGWrbaCYenS1vxjaNszSf5D+sJRcDiUFhMxo4lpTPI3Dynu6iN irVesVMthZv1SsAjpziihKTPj+TEyP64v784Y16p2xXwS27P9/ciCLiC03ET ULV3iJhYmDLjsNgmCblCFEn5ZnmpqbPk1+lpqNJINPpJijqiGPa5aVcGGxa6 islKBnW7YLbGe9fXx7j1WHoKOMuZqrfaKgUUt5kqiixWpnMcu7xr1QmKTV 3cXX0a9OzaaoyGro2LoSdDngkuLjefMthoeg4Vfb/DVqB23NLtm/FkUih89 bZVqhVPmQ9t9VxRJMhOlzlspRkf/ctDxaAxcMc6SkpkT6FGSwKpdfO3EJ /KlbBUDVyJ8aYuWjx17lyXC0zPoLFwErrYxQfDj7SM4tQZbI3TqQRliqSK9 ajSnCGzkqlk8t+rsM3uke2X08QwsGflpXTkEM2YkMDePUxYlw5dXmmbwr Tati8nNXOAKgW4BC28uHis3RUKkttLx1H/qCt7F+QirYjFrq2sljLSrQ3xgIb r2G1itCAKAAA7"); |
1 | data:[<mime type>][;charset=<charset>][;base64],<encoded data> |
The encoding is indicated by ;base64. If it’s present the data is encoded as base64. Without it 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 is omitted, it defaults to text/plain;charset=US-ASCII. (As a shorthand, the type can be omitted but the charset parameter supplied.)
Online Conversion – Base64 converter for embedded URI Images from A Blue Star
Clipboard Observer – a free java tool for converting PNG files to URI scheme easily (You need Java JRE or JDK environment to run this application)
Data URI Maker for UNIX from Sveinbjorn Thordarson’s Website (standard command line tool script)
Data URI Maker for Mac OS X from Sveinbjorn Thordarson’s Website
CSSEmbed – Automatic data URI embedding in CSS files, a tool to automatically embed images into CSS files as data URIs by Nicholas C. Zakas

Like most of us believes, URIs are not just a way to embed images inside an HTML or CSS file, there is nothing here which is image-specific. We can encode and embed any type of files like fonts CSS or even HTML itself. Data URI is a beautiful concept in the Web, and is going to get more momentum soon once IE gives full support. But it’s a good sign that IE started giving partial support from version 8.0 onwards. For the time being, it seems that they are best suited to performance-related tasks.
http://en.wikipedia.org/wiki/Data_URI_scheme
http://www.w3.org/Addressing/URL/URI_Overview.html
http://www.websiteoptimization.com/speed/tweak/inline-images/
http://www.phpied.com/data-uris-mhtml-ie7-win7-vista-blues/
http://www.nczonline.net/blog/2009/10/27/data-uris-explained/
http://www.stevesouders.com/blog/2009/11/16/cssembed-automatically-data-uri-ize/
[...] on http://deepubalan.com/blog/2009/12/20/what-is-data-uri-scheme/ Share and [...]
[...] This post was mentioned on Twitter by thedsign, thedsign. thedsign said: RT @tweetmeme What is Data URI scheme? Very interesting read… http://bit.ly/6XN1iK [...]
Social comments and analytics for this post…
This post was mentioned on Twitter by FWebDe RT: @thedsign: RT @tweetmeme What is Data URI scheme? Very interesting read… http://bit.ly/6XN1iK…
What is Data URI scheme? @ Deepu Balan – Scribblings of a cyber geek…
A detailed blog post about Data URI scheme, Its advantages and Disadvantages, Browser compatibility. Explained with examples. Must Read!…
[...] What is Data URI scheme? [...]
What is Data URI scheme? @ Deepu Balan – Scribblings of a cyber geek…
Have you ever felt the need for holding an embedded image inside an HTML file, without referring to an external image file? Personally I felt like so many occasions, where the need for a completely self contained HTML page, with all its supporting imag…
Thursday, 24 December, 2009 at 6:31
Solid writeup but you’d be remiss to not bring up CSSEmbed
http://github.com/nzakas/cssembed
http://www.stevesouders.com/blog/2009/11/16/cssembed-automatically-data-uri-ize/
Also Divya’s post has some good stuff, though similar:
http://nimbupani.com/using-data-uris-in-css.html
Thursday, 24 December, 2009 at 12:31
Thanks for those links Paul. Thanks a lot for bringing CSSEmbed to my attention, It’s really a cool tool and I have updated this post by adding CSSEmbed download link under ‘Conversion Tools’. I am planning another detailed post on embedding other major types like fonts, HTML, CSS etc. I will definitely be mentioning about CSSEmbed in detail there. Personally I do not like long-scrolling blog posts in plain text, that’s the main reason I focused more on ‘basic URI concept using images’ alone in this post.
Friday, 1 January, 2010 at 12:25
Very informative and detailed post. Thanks for sharing.
Friday, 8 January, 2010 at 23:17
Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!
Saturday, 6 February, 2010 at 21:37
Super-Duper site! I am loving it!! Will come back again – taking your feeds too now, Thanks.
Monday, 5 April, 2010 at 4:45
Hello i am new on this board i hope i will be able to help & contribute here because i have learned allot myself.
Thank you
[URL=http://deelowdesigns.com][B]web design essex[/B][/URL]