Isn't it silly that a tiny favicon requires yet another HTTP request? How can I put the favicon into a sprite?

Everybody knows how to set up a favicon.ico link in their HTML:

<link rel="shortcut icon" href="" type="image/x-icon">

But it’s silly that for only a several-byte-tiny icon we need yet yet another potentially speed-penalizing HTTP request.

So I wondered, how could I make that favicon part of a usable sprite (e.g. background-position=0px -200px;) that doubles as say a logo in the rest of the website, in order to speed up the site and save that precious and valuable HTTP request. How can we get this to go into an existing sprite image along with our logo and other artworks?

14 thoughts on “Isn't it silly that a tiny favicon requires yet another HTTP request? How can I put the favicon into a sprite?”

  1. The proper solution is to use HTTP pipelining.

    HTTP pipelining is a technique in which multiple HTTP requests are written out to a single socket without waiting for the corresponding responses. Pipelining is only supported in HTTP/1.1, not in 1.0.

    It’s required that servers support it, but not necessarily partipate.

    HTTP pipelining requires both the client and the server to support it. HTTP/1.1 conforming servers are required to support pipelining. This does not mean that servers are required to pipeline responses, but that they are required not to fail if a client chooses to pipeline requests.

    Many browser clients don’t do it, when they should.

    HTTP pipelining is disabled in most browsers.

    • Opera has pipelining enabled by default. It uses heuristics to control the level of pipelining employed depending on the connected server.
    • Internet Explorer 8 does not pipeline requests, due to concerns regarding buggy proxies and head-of-line blocking.
    • Mozilla browsers (such as Mozilla Firefox, SeaMonkey and Camino), support pipelining however it is disabled by default. It uses some heuristics, especially to turn pipelining off for IIS servers.
    • Konqueror 2.0 supports pipelining, but it’s disabled by default.[citation needed]
    • Google Chrome does not support pipelining.

    I would recommend you try enabling pipelining in Firefox and try it there, or just use Opera (shudder).

  2. Good point and nice idea, but impossible. A favicon needs to be a single, separate resource. There is no way to combine it with another image file.

  3. I’m sorry, but you can’t combine the favicon with another resource.

    This means you have basically two options:

    1. If you’re comfortable with your site not having a favicon – you can just have the href point to a non-icon resource that is already being loaded (e.g. a style sheet, script file, or even some resource that benefits from being pre-fetched.)
      (My brief testing indicates that this works across most, if not all, major browsers.)

    2. Accept the extra HTTP request and just make sure your favicon file has aggressive HTTP cache-control headers set.
      (If you have other websites under your control, you might even have them sneakily preload the favicon for this website – along with other static resources.)

    P.S. Creative solutions that will not work:

    • The the weird CSS data-uri trick (linked to by commenter Felix Geenen) does not work.
    • Using Javascript to perform a delayed injection of the favicon <link> element (as suggested by user @yc) will likely just make things worse – by resulting in two HTTP requests.
  4. You could try a data URI. No HTTP request!

    <link id="favicon" rel="shortcut icon" type="image/png" href="data:image/png;base64,....==">

    Unless your pages have static caching, your favicon wouldn’t be able to be cached, and depending on the size of your favicon image, your source code could get kind of bloated as a result.

    Data URI favicons seems to work in most modern browsers; I have it working in recent versions of Chrome, Firefox and Safari on a Mac. Doesn’t seem to work in Internet Explorer, and possibly some versions of Opera.

    If you’re worried about Old IE (and you probably shouldn’t be these days), you could include an IE conditional comment that would load the actual favicon.ico in the traditional way, since it seems that older Internet Explorer doesn’t support Data URI Favicons

    `<!--[if IE ]><link rel="shortcut icon" href=""  type="image/x-icon" /><![endif]--> `
    1. Include the favicon.ico file in your root directory to cover browsers that will request it either way, since for those browsers, if they’re already checking no matter what you do, you might as well not waste the HTTP request with a 404 response.

    You could also just use the favicon of another popular site which is likely to have their favicon cached, like, so that it is served from cache.

    As commenters have pointed out, just because you can do this doesn’t mean you should, since some browsers will request favicon.ico regardless of the tricks we devise. The amount of overhead you’d save by doing this would be minuscule compared to the savings you’d get from doing things like gzipping, using far-future expires headers for static content, minifying JavaScript files, putting background images into sprites or data URIs, serving static files off of a CDN, etc.

  5. I found an interesting solution on this page. It is german but you will be able to understand the code.

    You put the base64 data of the icon into an external stylesheet, so it will be cached. In the head of your website you have to define the favicon with an id and the favicon is set as a background-image in the stylesheet for that id.

    link#icon {

    and the html

            <link id="icon" rel="shortcut icon" type="image/x-icon" />
            <link rel="stylesheet" type="text/css" href="/styles.css" />
  6. I think for the most part it does not result in another HTTP request as these are usually dumped in the browser’s cache after the first access.

    This is actually more efficient than any of the proposed “solutions”.

  7. Not really an answer to the question but simply to compliment the answers given by Marcel and yahelc I offer an elegant solution to the 404 favicon issue.

    Because some apps and browsers and whatnot check for a and if the icon is not found in the site root you can simply respond to the request with the 204 response header.

    Apache Examples:

    Apache option one (and my favorite), simple one liner in your .htacces or .conf:

    Redirect 204 /favicon.ico

    Apache option two:

    <Files "favicon.ico">
        ErrorDocument 204 ""

    For further reading, there is nice blog post by Stoyan Stefanov at

  8. Here’s the easiest way:

    <!DOCTYPE html><html><head> 
    <link rel="shortcut icon" href="data:image/png;base64,

    What icon it represents? Answer and upvote below!

  9. A minor improvement to @yc’s answer is injecting the base64-encoded favicon from a JavaScript file that would normally be used and cached anyway, and also suppressing the standard browser behavior of requesting favicon.ico by feeding it a data URI in the relevant meta tag.

    This technique avoids the extra http request and is confirmed to work in recent versions of Chrome, Firefox and Opera on Windows 7. However it doesn’t appear to work in Internet Explorer 9 at least.


    <!doctype html>
    <html lang="en">
            <meta charset="utf-8">
            <!-- Suppress browser request for favicon.ico -->
            <link rel="shortcut icon"type="image/x-icon" href="data:image/x-icon;,">
            <script src="script.js"></script>


    var favIcon = "\
    [...truncated for brevity...]
    var docHead = document.getElementsByTagName('head')[0];       
    var newLink = document.createElement('link');
    newLink.rel = 'shortcut icon';
    newLink.href = 'data:image/png;base64,'+favIcon;
    /* Other JS would normally be in here too. */


  10. You could use base64 encoded favicon, like:

    <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAACbUlEQVRIx7WUsU/qUBTGv96WSlWeEBZijJggxrREdwYixMnByYEyOvgfsBAMG0xuDsZ/QGc3NDFhgTioiYsmkhBYGLSBkLYR0va8gSjvQXiIT7/l5ibfOd/v3pN7gSmVSMTj8ThRfzdYk8lkMpl83/+AVFVVVXU0eHiVJEmSpB8DIcpkMplsdhCYz+fzhQJROBwOh8PDQN+oQCAQCASIRFEURZHI45GkP0/e7Xa73e70AMJnjel0Op1OA6oaDB4eAkAw6PcDvZ5t6zrw/Hx2trAw/cHYZ426ruu6DtzcGEYuBzQa19etFvD4WKtls4AoRqMPDwBjjLGPrt84ilgsFovF6EOapmmaRiP6O/jbAIguL4vFYpHGqlKpVCoVomq1Wq1Wibxer9fn+w+Q9+cUiUQikQhNrfdgWZZlWf4yyGhj27Zt254MUK/X6/X6F0aiKIqiKIOCYRmGYRjGZADLsizLIgqFQqHV1SkAnp5OTn79ItK0qyuPZ7SxaZqmaU4GKJfPzxmbfAPc/f3pqaIQLS8vLtZqgOP0bYyJoiAARC5Xrwf4/Vtbb2+Th1YqlUqlErC01GgkEkCz2WxyHLC+LsuiCAiCJLlcgM+3vd3pcBzXaJTLR0dEs7Ptdv+D4TiOG/A6DsBxQKvV621sAGtru7vl8ngAjuvXv7xcXIgiwNjMjCj2h+k4fQfPA4LA8xwHCO323V2hABiG223bwPy8xwMAbvfcHGMAY32j47y+3t4OAsZpZ2dzEwAsy7IcBxAExhwHMIxOx3GAlZVUyjT/1WFIudzenstFlEpFo9M8o+Pj/X2eJzo4SCR4fnzdb2N4Pyv9cduVAAAAAElFTkSuQmCC" rel="icon" type="image/x-icon" /> 
  11. Does it really matter?

    Many browsers load the favicon as a low priority so that it doesn’t block the page load in anyway, so yes it’s an extra request but it’s not on any critical path.

    The accepted solution is horrible as until the JS has been retrieved and executed all the DOM elements below will be blocked from rendering and it doesn’t reduce the number of requests!

  12. Killer Solution in 2020

    This solution necessarily comes nine years after the question was originally asked, because, until fairly recently, most browsers have not been able to handle favicons in .svg format.

    That’s not the case anymore.


    1) Choose SVG as the Favicon format

    Right now, in June 2020, these browsers can handle SVG Favicons:

    • Chrome
    • Firefox
    • Edge
    • Opera
    • Chrome for Android
    • KaiOS Browser

    Note that these browsers still can’t:

    • Safari
    • iOS Safari
    • Firefox for Android

    With the above in mind, we can now use SVG Favicons with a reasonable degree of confidence.

    2) Present the SVG as a Data URL

    The main objective here is to avoid HTTP Requests.

    As other solutions on this page have mentioned, a pretty smart way to do this is to use a Data URL rather than an HTTP URL.

    SVGs (especially small SVGs) lend themselves perfectly to Data URLs, because the latter is simply plaintext (with any potentially ambiguous characters percentage-encoded) and the former, being XML, can be written out as a long line of plaintext (with a smattering of percentage codes) incredibly straightforwardly.

    3) The entire SVG is a single Emoji

    In December 2019, Leandro Linares was one of the first to realise that since Chrome had joined Firefox in supporting SVG Favicons, it was worth experimenting to see if a favicon could be created out of an emoji:

    Linares’ hunch was right.

    Several months later (March 2020), Code Pirate Lea Verou realised the same thing:

    And favicons were never the same again.

    4) Implementing the solution yourself:

    Here’s a simple SVG:

      viewBox="0 0 16 16">
      <text x="0" y="14">🦄</text>

    And here’s the same SVG as a Data URL:


    And, finally, here’s that Data URL as a Favicon:

    <link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns=''%20viewBox='0%200%2016%2016'%3E%3Ctext%20x='0'%20y='14'%3E🦄%3C/text%3E%3C/svg%3E" type="image/svg+xml" />

    5) More tricks (…these are not your parents’ favicons!)

    Since the Favicon is an SVG, any number of filter effects (both SVG and CSS) can be applied to it.

    For instance, alongside the White Unicorn Favicon above, we can easily make a Black Unicorn Favicon by applying the filter:

    style="filter: invert(100%);"

    Black Unicorn Favicon:

    <link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns=''%20viewBox='0%200%2016%2016'%3E%3Ctext%20x='0'%20y='14'%20style='filter:%20invert(100%);'%3E🦄%3C/text%3E%3C/svg%3E" type="image/svg+xml" />
  13. You can use 8-bit PNG instead of ICO format for even smaller data footprint. Only thing you have to change is using “data:image/png” instead of “data:image/x-icon” MIME type header:

      rel="icon" type="image/png"

    “type” attribute can be “image/png” or “image/x-icon”, both works for me.

    You can convert ICO to 8-bit png using gimp or convert:

    convert favicon.ico -depth 8 -strip favicon.png

    and encode PNG binary to base64 string using base64 command:

    base64 favicon.png

Leave a Comment