192

How can I change the default favicon that is set by the Angular CLI?

I have tried many things, but it always shows the Angular logo as the favicon, even though I have deleted that icon (favicon.ico in src folder). It still shows, and I don't know from where it's loaded from.

I have replaced that icon with another icon, but it still show the Angular logo:

<link rel="icon" type="image/x-icon" href="favicon.ico">
chrisly
  • 55
  • 6
  • 3
    Possible duplicate of [How do I force a favicon refresh](http://stackoverflow.com/questions/2208933/how-do-i-force-a-favicon-refresh) – Matsemann May 07 '17 at 11:29
  • Running app with different port solves the problem. example: `ng s --port 4201` – Sajad May 24 '18 at 09:43
  • I am having same issue. In my case locally everything is good but when I deploy to server I get 500 internal server error... – Ziggler Aug 08 '18 at 22:17
  • I read all the answer which helped me a little bit but honestly that should not be so complicated for a so basic need: just a path to copy image to ,then possibly a config file, then a restart. the "refresh" answer are not helping. – pdem Nov 07 '19 at 08:42
  • A favicon is a static file that is specially configured in angular.json , just let the default and see here how it works :https://stackoverflow.com/questions/40424907/whats-the-default-path-for-static-files-in-angular2 – pdem Nov 07 '19 at 08:52

33 Answers33

269

Make a png image with same name (favicon.png) and change the name in these files:

index.html:

<link rel="icon" type="image/x-icon" href="favicon.png" />

angular-cli.json:

"assets": [
    "assets",
    "favicon.png" 
],

And you will never see the angular default icon again.

Size should be 32x32, if more than this it will not display.

NOTE: This will not work with Angular 9

For angular 9 you have to put favicon inside assets then give path like

<link rel="icon" type="image/x-icon" href="assets/favicon.png">
Guillaume
  • 21,685
  • 6
  • 63
  • 95
Sukhveer Singh
  • 2,847
  • 2
  • 10
  • 12
78

Since you have replaced the favicon.ico file physically, there must be a caching issue somewhere. There is a cache in your browser. Force it to get flushed by pressing Ctrl+F5.

If the default icon is still displayed, try another browser with a clean cache (i.e. you haven't visited the page with that browser yet).

Clear Cache Shortcuts: (Source)

Windows
IE:Ctrl+R; Firefox:Ctrl+Shift+R; Chrome:Ctrl+R, or Ctrl+F5, or Shift+F5.

Mac
Safari:+R; Firefox/Chrome:+Shift+R.

robinCTS
  • 5,746
  • 14
  • 30
  • 37
Yuri
  • 4,254
  • 1
  • 29
  • 46
39

Navigating to the file finally fixed this for me. In my case: http://localhost:4200/favicon.ico

I had tried to refresh, stop and start ng serve again, and "Empty Cache and Hard Reload", none worked.

Chau Nguyen
  • 894
  • 8
  • 13
34

The ensure the browser downloads a new version of the favicon and does not use a cached version you can add a dummy parameter to the favicon url:

<link rel="icon" type="image/x-icon" href="favicon.ico?any=param">
Tobi
  • 2,001
  • 2
  • 27
  • 49
21

we can change angular CLI favicon icon. we have to put icon file in "assets" folder and give that path in index.html.

<link rel="icon" type="image/x-icon" href="./assets/images/favicon.png"> It's work for me.

jaimin patel
  • 209
  • 2
  • 3
13

For Angular 6, put favicon.png of size 32x32 in the asset folder and change the path in index.html. Then,

<link rel="icon" type="image/x-icon" href="./assets/favicon.png">
pvy4917
  • 1,768
  • 17
  • 23
user1795667
  • 423
  • 4
  • 11
10

I was struggling with this as well, thinking I was doing something wrong with Angular, but my issue ended up being Chrome caching the icon. The standard "Empty Cache and Hard Reload" or restarting the browser weren't working for me, but this post pointed me in the right direction.

This specifically worked for me:

If on windows and using chrome, (exit chrome from taskbar) then go to C:\Users\your_username\AppData\Local\Google\Chrome\User Data\Default and delete the files Favicons-journal, Favicons then re-start chrome (from the taskbar, kill all instances).

There are lots of other good suggestions in that post if this doesn't work for you.

Badda
  • 1,329
  • 2
  • 15
  • 40
Jdevince
  • 191
  • 2
  • 7
  • 1
    This will also remove icons for any existing bookmarked pages, until you next visit the page. This did the trick for me though. – David B Apr 13 '18 at 09:23
7

Make a icon image with the extension .ico and copy and replace it with default favicon file in src folder.

index.html:

<link rel="icon" type="image/x-icon" href="favicon.ico" />

angular.json:

**"assets": [
          "src/favicon.ico",
          "src/assets"
        ],**
Aathil Ahamed
  • 460
  • 4
  • 16
5

TO RELOAD FAVICON FOR ANY WEB PROJECT:

Right click on the favicon and click 'reload'. Works every time.

Brian B
  • 310
  • 2
  • 5
4

Move favicon.ico to your assets and then to img folder, and after that only change your icon link tag in header. It helps me when favicon was not displayed at all.

KGROZA
  • 63
  • 7
  • In Chrome and Firefox, it was not a caching problem. I moved my ICO file, and Chrome and Firefox both immediately updated. – Steve11235 Dec 12 '17 at 22:12
  • I updated my favicon.ico file and it wouldn't load. I did this (moved to assets and updated links) and worked fine. – David Feb 28 '18 at 05:26
3

For future readers, if this happens to you, your browser wants to use the old cached favicon.

Follow these steps:

  1. Hold CTRL and click the "Refresh" button in your browser.
  2. Hold Shift and click the "Refresh" button in your browser.

Fixed.

3

Please follow below steps to change app icon:

  1. Add your .ico file in the project.
  2. Go to angular.json and in that "projects" -> "architect" -> "build" -> "options" -> "assets" and here make an entry for your icon file. Refer to the existing entry of favicon.ico to know how to do it.
  3. Go to index.html and update the path of the icon file. For example,

  4. Restart the server.

  5. Hard refresh browser and you are good to go.
Rut Shah
  • 1,093
  • 11
  • 13
3

Ok, here in 2020 on 9.1.12. I don't understand why exactly this process is so difficult. I followed almost every post above and none of them worked for me.

What DID work was this: Totally removing the favicon reference in index.html. It's totally counter intuitive but it works. You DON'T need to put it in the assets folder. I tried all of that but unfortunately none of those suggestions worked.

index.html

<!-- <link rel="icon" type="image/x-icon" href="favicon.ico"> DELETE THIS -->

angular.json

"assets": [
  "src/favicon.ico",
  "src/assets"
],

and when I run ng build --prod, the favicon is there. Displays on my live server too.

user2619824
  • 478
  • 1
  • 5
  • 20
2
<link rel="icon" type="image/x-icon" href="#">

Add source of your icon and restart app it will change.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Adeel
  • 133
  • 2
  • 4
  • 14
2
<link rel="icon" type="image/x-icon" href="./assets/myimage.png">

single period

Steve Nginyo
  • 303
  • 3
  • 12
1

as simple and easy as :

  1. add your icon or png in the same directory as favicon
  2. edit .angular-cli.json, in assets remove favicon.ico put yours in place
  3. edit index.html, search favicon and put yours in place
  4. run ng serve again

that's done

byxor
  • 5,930
  • 4
  • 27
  • 44
gxmad
  • 1,650
  • 4
  • 23
  • 29
1

I was playing around with this for a little while. Turns out that the favicon is apparently handled by a node module called @scematics (at least in Angular5).

You can change your favicon in this folder:

[YourProjectName]\node_modules\@schematics\angular\application\files\__sourcedir__

In that folder there should be a favicon.ico, that's the one that is loaded. Im pretty shure this doesnt apply to everyone but it worked out for me.

Hope this helped. Happy coding! :D

1

For those needing a dynamically added favicon here is what I did with an app initializer:

import { APP_INITIALIZER, FactoryProvider } from '@angular/core'

export function faviconInitFactory () {

 return () => {
  const link: any = document.querySelector(`link[rel*='icon']`) || document.createElement('link')
  link.type = 'image/x-icon'
  link.rel = 'shortcut icon'

  if (someExpression) {
    link.href = 'url' || 'base64'
  } else {
    link.href = 'url' || 'base64'
  }

  document.getElementsByTagName('head')[ 0 ].appendChild(link)
}

}

export const FAVICON_INIT_PROVIDER: FactoryProvider = {
  provide: APP_INITIALIZER,
  multi: true,
  useFactory: faviconInitFactory,
  deps: []
}

Just remove fav.ico file under src/ and add this. The favicon will be added before app start

Danny Fenstermaker
  • 914
  • 10
  • 12
1

I tried many of these solution but was unsuccessful. The one that worked for my angular 5 application was the below:

index.html: Comment out your link tag

 <!-- <link rel="icon" type="image/png" href="src/assets/images/favicon.ico"> --> 

.angular-cli.json: leave the item type as ".ico"

 "assets": [
      "assets",
      "favicon.ico"
    ],

LASTLY..

  • In your project folder structure, have the favicon.ico inside the src ex: (C:\Dev\EPS\src). You do NOT need to have it in your asset folder since you aren't referencing it.

  • Make sure your icon is not broken (Your icon should be readable if viewed through window explorer aka no broken window icon)

  • must be 32 x 32 dimension
Maurizio L
  • 43
  • 1
  • 6
1

Follow these steps to change icon from default angular to an application specific one.

  1. For AngularJS Projects: Add the icon inside the webapps. Inside the index.html file add the following line

<link rel = "icon" type = "image/x-icon" href = "location of specifed icon inside webapps directory"> in the head tag.

  1. For projects based on Angular 7/8: Add the icon image to assets folder. Go to index.html file inside the project. Change the following link tag

<link rel = "icon" type = "image/x-icon" href = "favicon.ico"> TO <link rel = "icon" type = "image/x-icon" href = "assets/fileName">

This should modify the default angular icon to your specified icon.

EdwardFunnyHands
  • 103
  • 2
  • 11
0

Make sure when you use icon image it is not manipulated extension, like if you download a png image and then manually change its extension from png to icon. In this case, your image will be corrupted. And browser does not understand.

I did this mistake, but after using original icon image its start working.

wscourge
  • 10,657
  • 14
  • 59
  • 80
0

1.Check your link tag on index.html file that it should look like this.

<link red="icon" type="image/x-icon" href="favicon.ico">

2.Check file name of favicon.ico in /src directory.

3.Rerun Angular with ng serve and refresh application.

4.If it doesn't show (or something look like it buffer old favicon.ico file). try to refresh path of favicon again to load favicon.ico file (eg. refresh yourdomain.com/favicon.ico)

Community
  • 1
  • 1
dscanon
  • 275
  • 3
  • 6
0

I had the same problem.

If you are using a Mac, you will need to empty the Cache (Option++E) and reload the page in addition to restarting the app (and of course changing the path in index.html).

robinCTS
  • 5,746
  • 14
  • 30
  • 37
alang
  • 1
0
  1. Remove your existing favicon.ico
  2. Add new icon into the src folder with name as "favico.ico"
  3. Clear Cache in your browser.

The icon does not reflect only because of your browser cache. Sometimes try restarting the application

Sri Vivek
  • 525
  • 7
  • 9
0

Following steps worked for me.

  1. Remove default "favicon.ico" file with a new one with different name i.e. "_favicon.ico" in my case.

    Note :: Don't keep the default name, as it's get's cached in your browser and difficult to overwrite with new icon.

  2. Update index.html with new link tag i.e.

     <link rel="icon" type="image/x-icon" href="_favicon.ico" /> 
    
  3. Update .angular-cli.json with new icon name i.e. "_favicon.ico".

  4. Build & launch your app, and do a hard refresh Ctrl+F5.

Community
  • 1
  • 1
0
<link rel="icon" type="image/x-icon" href="assets/liana.jpg">

"assets": [

        "assets/sorry.jpg",
        "assets/liana.jpg"

  ],

this worked for me.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
0

In my case, the problem was that I had different dimensions compared to normal one. I had 48x48 px whereas it was expecting 32x32 px and my extension was png so I had to change it to ico

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
0

What really works for me was putting my favicon into assets folder and apear automatically in the browser.

  1. change location to assets folder inside src folder.
  2. change index.html like this <link rel="icon" type="image/x-icon" href="assets/favicon.png">
Okyam
  • 700
  • 6
  • 19
0

An editor (in my case IDEA 2020.2) can sometimes add src/ prefix to icon location in href. I mean

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

instead of

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

So in this case you should remove this src/ part in href. This solved the problem for me.

Артур Гудиев
  • 1,004
  • 2
  • 10
  • 26
0

If upgarde angular to 8+ you must change in angular.json

"assets": [
  "assets",
  "favicon.ico"
]

to

"assets": [
  {
    "glob": "**/*",
    "input": "src/assets/",
    "output": "/assets/"
  },
  {
    "glob": "favicon.ico",
    "input": "src/",
    "output": "/"
  }
]
-1

Deleting chromes favicon cache and restarting the browser on the mac worked for me.

rm ~/Library/Application\ Support/Google/Chrome/Default/Favicons
Padawan
  • 770
  • 1
  • 8
  • 18
-1

I had the same issue, and solved it by forcing the refreshby the method described here:

To refresh your site's favicon you can force browsers to download a new version using the link tag and a querystring on your filename. This is especially helpful in production environments to make sure your users get the update.

<link rel="icon" href="http://www.yoursite.com/favicon.ico?v=2" />
maia
  • 3,910
  • 4
  • 27
  • 34
-1

I fixed the issue by creating my own .ico file and created a assets folder and put the file over there. Then changed the link href in Index.html

Jerin Kurian
  • 164
  • 2
  • 9