6 Feb 2010

I love that you can embed Base64-encoded images in CSS and that WebKit understands them.

Here, for example, is a way to add my Open in External App icon to links that you capture from a UIWebView to display in Mobile Safari:

a {
	color:rgb(50, 79, 133);
	text-decoration:none;
	padding-left:26px;
	background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAARCAYAAADDjbwNAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAKZJREFUeNpi+v//PwM9MBMDncDws4jFOKBNF0hfIkGPydkNVWfJ8dEcEvXMIctHQKwOZTMSof4/EOuSaxE/CerBjgEGN9xiYDAywvhANt6g+09JJAMt+Y/PAmSLPhERXLgw0ZZRLXmDLCNkER81LALFFaU+YsSD4ZYgJRDaBB0xlsCS9ycSkvh/tGBiJJSskX10k4jUhZzKLpBbqKaTqCeFHIsAAgwAk2iI07NfUtQAAAAASUVORK5CYII=);
	background-repeat:no-repeat;
}

Add Your Comment

Spam Protection by WP-SpamFree

Base64-encoded images as CSS backgrounds in UIWebViews

  1. I figured I’d bother you here instead of on twitter.

    So are you encoding the image or just the url? Because that’s not a lot of chars for an image. The part I’m confused about is how there is no file dependency if you’re simply encoding strings (URI’s).

    Arik Beremzon
  2. Hi Arik, it’s encoding the image (it just happens to be a tiny little icon) :)

    Aral