Create a Blank Favicon with Data

By  on  

I was recently setting up a virtual host and diving into development when I needed to debug a JavaScript issue.  One thing that started annoying me right away was the console message notifying me that the favicon.ico file couldn't be found.  I hadn't put one there and had no desire to...but that damn message was bugging the hell out of me.  I did a quick search and found a tiny data URL snippet to include a blank favicon within the page.

The HTML

The empty favicon is created with the LINK element:

<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />

Essentially, instead of linking the external ico file, the image data is placed in the HREF attribute.  Cool, huh?  No more annoying messages and no need to add another file to the repository.

Recent Features

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

Incredible Demos

  • By
    Implementing Basic and Fancy Show/Hide in MooTools 1.2

    One of the great parts of MooTools is that the library itself allows for maximum flexibility within its provided classes. You can see evidence of this in the "Class" class' implement method. Using the implement method, you can add your own methods to...

  • By
    Six Degrees of Kevin Bacon Using MooTools 1.2

    As you can probably tell, I try to mix some fun in with my MooTools madness but I also try to make my examples as practical as possible. Well...this may not be one of those times. I love movies and useless movie trivia so naturally I'm...

Discussion

  1. Michael Tully

    The exact same thing annoyed me in the exact same environment, thanks for the heads up Dave :)

  2. Hi david,
    Favicon is the thing which people generally forgot to add in site and they got very massive 404 error for that, which is not shown to user but affect the site loading time, Thanks for easy and quick solution…

    Avinash

  3. It’s also probably worth noting this could be used for making dynamic icons without saving data to your host. Like a pretty graphic that displays the user’s name? Just throw the href attribute into the src attribute of a image tag.

    IE6 is the only browser I have found this not to work on.

  4. Thats pretty cool, i’ve seen the base64 images like that before, does anyone know the full browser compatibility for using that?

  5. This is the best solution, no more calls to /favicon.icon!

  6. The W3C Validator uses this technique, too, to show if the site is valid or not in the URL bar.

    http://validator.w3.org/check?uri=http%3A%2F%2Fjanbuschtoens.de%2F

  7. Did you use any converter to turn your favicon into a long base64 string?
    Thanks!

  8. I’m pretty sure Data URIs don’t work in IE7.

    http://stackoverflow.com/questions/1765342/which-browsers-support-data-uris-and-since-which-version

    However, now that IE9 is out, SCREW IE7!

    And IE6 has been dead to me for nigh on 3 years. Except where I’m currently working. : (

  9. Thanks a lot :), have a nice day sir!

  10. I’d really like to hear more about that… is it possible to change the favicon using JavaScript while the page is loaded? That would be neat for WebApplications stuck in an unopened tab to notify the user that something has happened, for instance with aninstant messenging thingy.

  11. Peter

    Surely that should be “debugging the hell out of me”?

    Sorry… couldn’t resist!

    :-)

  12. JR

    Beware of Internet Explorer!!!

    As someone have said, this doesn’t work in IE6 or 7. In IE8 and above works.

    Nevertheless there are solutions to integrate images this way with MHTML
    http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/

  13. Interesting article! Do you know about setting base64 favicons globally with .htaccess? My website is configured to include the favicon regardless of what file you’re viewing, including images, CSS, and JavaScript files.

  14. thanks a lot dude. i manage to change my favicon with this tutorial.

  15. Valtteri

    With GIF it’s even smaller: data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw

    (IE ≥ 11)

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!