Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I didn't include the following line of code in my head tag, however my favicon still appears in my browser:
<link rel="icon" href="favicon.ico" type="image/x-icon" />
What's the purpose of including it?
–
You should in fact do both, so that all browsers will find the icon.
Naming the file "favicon.ico" and putting it in the root of your website is the method "discouraged" by W3C:
Method 2 (Discouraged): Putting the favicon at a predefined URI
A second method for specifying a favicon relies on using a predefined URI to identify the image: "/favicon", which is relative to the server root. This method works because some browsers have been programmed to look for favicons using that URI.
W3C - How to add a favicon to your site
So, to cover all situations, I always do that in addition to the recommended method of adding a "rel" attribute and pointing it to the same .ico file.
–
–
–
–
I can force a refresh of the icon by adding a query parameter for example ?v=2
. like this:
<link rel="icon" href="/favicon.ico?v=2" type="image/x-icon" />
In case I need to specify the path.
Many people set their cookie path to /. That will cause every favicon request to send a copy of the sites cookies, at least in chrome. Addressing your favicon to your cookieless domain should correct this.
<link rel="icon" href="https://cookieless.MySite.com/favicon.ico" type="image/x-icon" />
Depending on how much traffic you get, this may be the most practical reason for adding the link.
Info on setting up a cookieless domain:
http://www.ravelrumba.com/blog/static-cookieless-domain/
You do not need a 16x16 "favicon.ico" whatsoever. Use the HTML <link>
element(s) nested in your <head>
element. Web browsers will utilize very small images but the image sizes that Google requires and supports for displaying them in search results are multiples of 48 pixels.
Your favicon must be a multiple of 48px square, for example: 48x48px,
96x96px, 144x144px and so on. SVG files don't have a specific size.
Any valid favicon
format
is supported.
As an aside, and sort of unrelated point, In terms of displaying a logo in search results from structured data, they want an image of at least 112px.
So, something like below is what I use for favicons:
<link rel="icon" type="image/png" href="../media/favicon-336x336.png" sizes="336x336">
<link rel="icon" type="image/png" href="../media/favicon-288x288.png" sizes="288x288">
<link rel="icon" type="image/png" href="../media/favicon-240x240.png" sizes="240x240">
<link rel="icon" type="image/png" href="../media/favicon-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="../media/favicon-144x144.png" sizes="144x144">
<link rel="icon" type="image/png" href="../media/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="../media/favicon-48x48.png" sizes="48x48">
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.