I've been working on a website and I'd like to add a small icon to the browser tab.
How can I do this in HTML and where in the code would I need to place it (e.g. header)? I have a .png
logo file that I'd like to convert to an icon.
Related: HTML set image on browser tab.
Best Solution
There are actually two ways to add a favicon to a website.
<link rel="icon">
Simply add the following code to the
<head>
element:PNG favicons are supported by most browsers, except IE <= 10. For backwards compatibility, you can use ICO favicons.
Note that you don't have to precede
icon
inrel
attribute withshortcut
anymore. From MDN Link types:favicon.ico
in the root directoryFrom another SO answer (by @mercator):
So all you have to do is to make the
/favicon.ico
request to your website return your favicon. This option unfortunately doesn't allow you to use a PNG icon.See also favicon.png vs favicon.ico - why should I use PNG instead of ICO?