Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Adding a Favicon to a Site

, 14 Jan 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to add a favicon to a site

Introduction

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 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" />

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Cindy Potvin

Canada Canada
No Biography provided
Follow on   Twitter   Google+

Comments and Discussions

 
Questionrelated Pinmemberthewazz20-Jan-14 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 14 Jan 2014
Article Copyright 2014 by Cindy Potvin
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid