The Developer Bacon logo on a striped grey background.

How to setup a favicon

Published | 2 min read
Updated Mar 24, 2020

The short answer

The easiest way to set up a favicon (assuming that a web-sized image is already made) if by using the following code, and placing it in the <head> tag.

<link rel="icon" type="image/png" href="" />

The long answer

Setting up a favicon can be super easy once you get the hang of it. The simplest and quickest way is listed above, but what if you want to have different sizes of favicons for different devices and browsers?

PNG Sizes

To add different sizes to a favicon link you can just add a sizes attribute to the link tag. The typical sizes for favicons on most browsers are 16x16, 32x32 and higher. For some other browsers like Google Tv and Chrome on Android, the recommended sizes are 96x96 and 192x192 respectively. An example of these sizes would look like this.

<link rel="icon" type="image/png" sizes="16x16" href="" />
<link rel="icon" type="image/png" sizes="32x32" href="" />
<link rel="icon" type="image/png" sizes="96x96" href="" />
<link rel="icon" type="image/png" sizes="192x192" href="" />

ico file type

The primary way to set an icon would be to use a .ico file. While all modern browsers can read the png format, this is primarily used for older versions of IE. You can find plenty of favicon.ico generators online to build a properly formated ico file. The use of a favicon.ico file would look like this.

<link rel="icon" href="favicon.ico" />

Browsers will also be able to find the ico file if it is just left on the root of the site and not declared in a meta tag.

SVG's icons

A few browsers including Chrome and Firefox recently added support for SVG favicons. If you want to see what browsers support this at the time of reading the check out To use this new feature you will need a SVG version of your websites favicon and add this link to the head of your site. Make sure to include the sizes="any" or the browser will download the file even if it can't display that as the favicon.

<link rel="icon" sizes="any" href="/favicon.svg" type="image/svg+xml" />

CSS color scheme media changing favicons

If you are using the prefers-color-scheme media query on your website and would like to change the favicon for each theme then all you need is a dark and/or light version of your favicon and a media attribute.

<link rel="icon" media="prefers-color-scheme: dark" href="favicon-light.ico" />
<link rel="icon" media="prefers-color-scheme: light" href="favicon-light.ico" />