in CodeProject

Adding a favicon to a site

I forgot to make a favicon when I created the theme for this site, so let’s fix this. A favicon is the small icon that appears beside the title in the tab, and that is shown when the user bookmarks your site. According to the W3C, the favicon should be a .PNG, .GIF or. ICO image that’s 32×32 pixels or 16×16 pixels. So I created a .PNG image that is 32×32 pixels so it will look nice scaled down, and is a nice starting size if some browsers display it bigger. I also added the following tag to the head of each page :

<link rel="icon" type="image/png" href="http://www.cindypotvin.com/favicon.png" />

Unfortunately, Internet Explorer only supports .ICO for favicons, even Internet Explorer 10, so I had to also add the following in the head:

<link rel="shortcut icon" type="image/x-icon" href="http://www.cindypotvin.com/favicon.ico" />

Depending on the browser and the order of the declarations, the .PNG or the .ICO will be used, but since it’s the same image it’s good enough for me and respects the standard. Everything now works in Internet Explorer, Chrome and Firefox on the desktop, but it will not work with mobile devices. When a the web site is added to the home screen in iOS or Android, the favicon will not be shown. iOS looks for a link tag in the head of the page with the rel=apple-touch-icon, which adds the 3D effect in iOS 6 or earlier (iOS 7 icons stays flat), or rel=apple-touch-icon-precomposed that displays the image without embellishments. Android phones will also recognise apple-touch-icon and apple-touch-icon-precomposed for the home screen images, so this is enough for both platforms. If you want to support older phones, Android 2.1 will only recognize apple-touch-icon-precomposed. I wanted to keep the same flat look as my theme, so I used the –precomposed attribute and the same icon as earlier :

<link rel="apple-touch-icon-precomposed" href="http://www.cindypotvin.com/favicon.png" />

Using the same icon will make it stretched on every device, since the default size is 60×60. You can add icons specific for each platform with apple-touch-icon if you need a bit more control :

<link rel="apple-touch-icon-precomposed" href="http://www.cindypotvin.com/touch-icon-iphone.png" />
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="http://www.cindypotvin.com/touch-icon-ipad.png" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="http://www.cindypotvin.com/touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="http://www.cindypotvin.com/touch-icon-ipad-retina.png" />

Want to learn new programming skills quickly?

Subscribe to my newsletter to receive my 5 Hacks to Learn New Skills email course directly in your inbox.

You’ll also receive updates about what's going on with the blog.

Write a Comment

Comment