Font-awesome icons not loading on Angular4 project

21,094

Solution 1

You should be using the class fa instead of fas. The fa class sets the font-face. (hat tip to @mike-hill)

View source on http://fontawesome.io/icon/address-card/

Solution 2

Font-awesome version 5+

fa prefix has been depricated from version 5. In order to use fas prefix install version 5+ and include in your styles.

install:

yourapp$npm install @fortawesome/fontawesome-free --save

package.json

"styles": [
   "node_modules/@fortawesome/fontawesome-free/css/all.css",
   "src/styles.scss"
  ],

Solution 3

After adding dependencies to Angular.json or Angular-cli.json. 1) stop running App 2) start it It will recognize new resources

Solution 4

First make sure you have properly setup the project requirements to use font-awesome icons by including them in styles[] in angular.jason or simply importing them by like this:

@import "~font-awesome/css/font-awesome.css";

in the component css file. Then it is necessary to have "fa" class in addition to what the font-icons markup gives you. Alternatively you can do like this:

<div class="fa">
<i class="whateverTheIconClassYouWant"></i>
</div>

Inside the div with class="fa" you can directly copy paste the code that is provided in font awsome website.

Hope this helps! Happy coding!!!!

Share:
21,094
Carlos Pisarello
Author by

Carlos Pisarello

Updated on June 08, 2020

Comments

  • Carlos Pisarello
    Carlos Pisarello about 4 years

    I'm working on an angular 4 project using font-awesome, i followed this guide to install the library with npm: How to add font-awesome to Angular 2 + CLI project

    i've configured the project to compile the scss stylesheets with the ng-serve command, my styles paths of the angular-cli.json looks like this:

    "styles": [
            "../node_modules/bootstrap/scss/bootstrap.scss",
            "../node_modules/bootstrap/scss/main.scss",
            "../node_modules/font-awesome/scss/font-awesome.scss"
    
          ],
    

    i want to make a button with an address card icon on it, i'm also working with Bootstrap 4, so it looks like this:

    <button class="btn btn-sm btn-primary"><span class="fas fa-address-card"></span></button>
    

    but when it loads, it looks like this:

  • Sebastian
    Sebastian over 6 years
    OMG it took me way too long to find this answer - why the hell do they generate the examples like this on the homepage? <i class="fas fa-home"></i>
  • Klooven
    Klooven about 6 years
    @bigbasti It is for Font Awesome 5. You are probably using an older version.
  • Naila Akbar
    Naila Akbar almost 5 years
    It took me almost 2 days to figure out my issue.. Thank you for mentioning to restart app after adding new resources..
  • Krishnadas PC
    Krishnadas PC about 3 years
    I think it should be added to the angular.json file not package.json