Click here to Skip to main content
13,086,248 members (85,768 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 14 Jan 2014

Adding a Favicon to a Site

, 14 Jan 2014
Rate this:
Please Sign up or sign in to vote.
How to add 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="" />

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

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

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="" />
<link rel="apple-touch-icon-precomposed" sizes="76x76" 

href="" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" 

href="" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" 

href="" />


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


About the Author

Cindy Potvin
Canada Canada
Cindy Potvin is a software developer based in the Montreal area. At her day job, she creates web applications using the ASP.NET MVC framework and mobile applications using the Android SDK.

You may also be interested in...


Comments and Discussions

Questionrelated Pin
thewazz20-Jan-14 5:55
memberthewazz20-Jan-14 5:55 

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

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

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