79

I integrated Font Awesome 5 in a project with bootstrap 4. When I recall a font via CSS it does not work. with Font Awesome 4 the code was as follows:

#mainNav .navbar-collapse .navbar-sidenav .nav-link-collapse:after {
  float: right;
  content: "\f107";
  font-family: "FontAwesome";
}

I tried to change the font name but it does not work

font-family: 'Font Awesome 5 Free'
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Carmelo Valenti
  • 793
  • 1
  • 6
  • 4

18 Answers18

202

Your Unicode is wrong f107

a::after {
  content: "\f007";
  font-family: 'Font Awesome\ 5 Free';
}
<link href="https://use.fontawesome.com/releases/v5.0.1/css/all.css" rel="stylesheet">
<a>User</a>
<i class="fas fa-shopping-basket"></i>

Or in other case, font-weight: 900; will save you. Some icons in font awesome 5 not working without font-weight: 900;.

a::after {
  content: "\f007";
  font-family: 'Font Awesome\ 5 Free';
  font-weight: 900;
}
Pedram
  • 15,766
  • 10
  • 44
  • 73
  • 6
    Work it. but for use f107 icon (avaiable only solid free) use [code] font-awesome/css/fontawesome.css" rel="stylesheet" /> font-awesome/css/fa-solid.css" rel="stylesheet" />[/code] – Carmelo Valenti Dec 13 '17 at 09:44
  • 1
    @CarmeloValenti But i used `All` version, it should work, but it still not working. – Pedram Dec 13 '17 at 09:47
  • 4
    It's a bug. including all icon, are not shown the icons "solid" that are not present in the "regular" package, so you have to exclude the (few) "regular" icons if you want to use all the "solid" – Carmelo Valenti Dec 13 '17 at 10:04
  • 3
    Hello, I have the same problem. @Carmelo, could you elaborate your answer better to make us understand? – Dev Dec 15 '17 at 16:45
  • 4
    I was banging my head on this for hours, font-weight: 900;is the thing! thanks – Shamseer Ahammed Jan 14 '19 at 10:31
  • 4
    font-weight to the rescue. AHhhh, wish i had come across this before. Would have saved me hours trying to figure this out! – Diego Apr 25 '19 at 00:32
  • 1
    +1 I needed single-quotes on `font-family` \o/ MacOS Chrome Version 75.0.3770.100 (Official Build) (64-bit) – danwild Jul 09 '19 at 03:52
  • 1
    Thank you! I was desperate for solution. Works like charm. – Ana Kochevska Feb 24 '20 at 12:11
  • 1
    Thank you. Even for `Font Awesome Free 5.13.0`, I still needed to add `font-weight: 900` to make icons like `f107` or `f106` work. – Hrishikesh Apr 30 '21 at 10:57
107

Strangely you must put the 'font-weight: 900' in some icons so that it shows them.

#mainNav .navbar-collapse .navbar-sidenav .nav-link-collapse:after {
  content: '\f107';
  font-family: 'Font Awesome\ 5 Free'; 
  font-weight: 900; /* Fix version 5.0.9 */
}
Lenin Zapata
  • 1,417
  • 1
  • 11
  • 14
  • 6
    Woah! Thanks for that 5.0.9 font-weight fix. That was the only thing missing in my code. – Julien B. Apr 08 '18 at 23:24
  • This already fixed on updated version with `.fa, .fas { font-weight: 900; }` – Pedram Apr 28 '18 at 07:15
  • Awesome! I'm using 5.1.0, still had to solve this with `font-weight:900;` – smartrahat Jul 01 '18 at 14:01
  • 3
    It's because the font weight is called in the `.fa, .fas` classes. If you're doing a custom class, including `:before` or `:after` pseudo classes, then it seems we still have to apply the `font-weight: 900;` value. – Okomikeruko Feb 19 '19 at 16:03
  • Even on 5.13.0, I had to add `font-weight: 900` for fixing it. Thank you! – Hrishikesh Apr 30 '21 at 10:55
26

The problem is in the font-weight.
For Font Awesome 5 you have to use {font-weight:900}

Maak
  • 4,720
  • 3
  • 28
  • 39
GRigol
  • 393
  • 4
  • 7
15

Using the fontawesome-all.css file: Changing the "Brands" font-family from "Font Awesome 5 Free" to "Font Awesome 5 Brands" fixed the issues I was having.

I can't take all of the credit - I fixed my own local issue right before looking at the CDN version: https://use.fontawesome.com/releases/v5.0.6/css/all.css

They've got the issue sorted out on the CDN as well.

 @font-face {
    font-family: 'Font Awesome 5 Brands';
    font-style: normal;
    font-weight: normal;
    src: url("../webfonts/fa-brands-400.eot");
    src: url("../webfonts/fa-brands-400.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-brands-400.woff2") format("woff2"), url("../webfonts/fa-brands-400.woff") format("woff"), url("../webfonts/fa-brands-400.ttf") format("truetype"), url("../webfonts/fa-brands-400.svg#fontawesome") format("svg"); }

    .fab {
    font-family: 'Font Awesome 5 Brands'; }
    @font-face {
    font-family: 'Font Awesome 5 Brands';
    font-style: normal;
    font-weight: 400;
    src: url("../webfonts/fa-regular-400.eot");
  src: url("../webfonts/fa-regular-400.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-regular-400.woff2") format("woff2"), url("../webfonts/fa-regular-400.woff") format("woff"), url("../webfonts/fa-regular-400.ttf") format("truetype"), url("../webfonts/fa-regular-400.svg#fontawesome") format("svg"); }
JTStuedle
  • 161
  • 1
  • 2
7

Requiring 900 weight is not a weirdness but a intentional restriction added by FontAwesome (since they share the same unicode but just different font-weight) so that you are not hacking your way into using the 'solid' and 'light' icons, most of which are available only in the paid 'Pro' version.

user3006765
  • 71
  • 1
  • 2
6

Since FontAwesome 5, you have to enable a new "searchPseudoElements" option to use FontAwesome icons this way:

<script>
  window.FontAwesomeConfig = {
    searchPseudoElements: true
  }
</script>

See also this question: Font awesome 5 on pseudo elements and the new Font Awesome API: https://fontawesome.com/how-to-use/font-awesome-api

Additionaly, change font-family in your CSS code to

font-family: "Font Awesome 5 Regular";
Mesa
  • 289
  • 2
  • 10
4

I didn't want to use the 'all' version, so searched the 'fontawesome-all.min.css' file (previously included in the header) for 'family' tag and found at the end a declaration @font-face{font-family:**Font Awesome\ 5 Free**;font-style:normal;

So, in the stylesheet for an element where I wanted to use the content: "\f0c8"; code, I've added (or changed to) font-family: Font Awesome\ 5 Free; and it worked.

.frb input[type="checkbox"] ~ label:before {
    font-family: Font Awesome\ 5 Free;
    content: "\f0c8";
    font-weight: 900;
    position: absolute;
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
WojCup
  • 83
  • 4
  • 1
    Thanks, I did similar but omitted font-weight: 900 which caused some icons not to work. This version seems a mess since it's not very backwards compatible, with some icons even getting new codes. – mhapps Feb 25 '18 at 20:44
4

Strangely you have to include the font-family and the font-weight for it to work. Here is what worked for me:

.second-section-header::after {
    content: "\f259";
    font-family: 'Font Awesome\ 5 Free';
    font-weight: 900;
}

From there, you can begin adding any styles that you want.

Let's say:

.second-section-header::after {
    content: "\f259";
    font-family: 'Font Awesome\ 5 Free';
    font-weight: 900;
    font-size: 100px;
    color: white;
    z-index: 1;
    position: absolute;
}

I hope this helps.

guzmonne
  • 2,490
  • 1
  • 16
  • 22
Leonard203
  • 61
  • 6
4

I had tried all above the solutions for Font Awesome 5 but it wasn't working for me. :(

Finally, I got a solution!

Just use font-family: "Font Awesome 5 Pro"; in your CSS instead of using font-family: "Font Awesome 5 Free OR Solids OR Brands";

Elliyas Ahmed
  • 101
  • 1
  • 1
  • 10
3

IF it's still not working for you, I had forgotten to add the fa-ul class onto the parent (UL) element:

<ul class="fa-ul">

Together with the 2 bits of advice provided already by others:

a) font-family: 'Font Awesome\ 5 Free';
b) font-weight: 900;

solved it for me.

FWIW, the include in my <head> tags is just:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />

And I am using this with React and Preact. No need for any special React npm installs or components.

cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • 1
    In my case, with Ver 5.20, the upper layer having a `font-weight: 500` resulted Font Awesome not display. Adding itself a `font-weight: N!important` where `N > 500` brings it back. Guess it is the way Font Awesome rendering cause some conflict. – seedme Sep 20 '21 at 03:23
2

npm i --save @fortawesome/fontawesome-free

My Sccs:

@import "~@fortawesome/fontawesome-free/scss/fontawesome";
@import "~@fortawesome/fontawesome-free/scss/brands";
@import "~@fortawesome/fontawesome-free/scss/regular";
@import "~@fortawesome/fontawesome-free/scss/solid";
@import "~@fortawesome/fontawesome-free/scss/v4-shims";

It worked fine for me!

Tan Nguyen
  • 386
  • 4
  • 9
1

the solution is call it like normal font:

@font-face {
font-family: "Font Awesome 5 Free-Regular-400";
src: url(../fonts/Font%20Awesome%205%20Free-Regular-400.otf) format("opentype");}
Menzezzz
  • 11
  • 2
  • 8
1

that's probably about pricing model... ;)

https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use

Solid    Free           fas   <i class="fas fa-camera"></i> 
Regular  Pro Required   far   <i class="far fa-camera"></i> 
Light    Pro Required   fal   <i class="fal fa-camera"></i> 
Brands   Free           fab   <i class="fab fa-font-awesome"></i>
Michal Miky Jankovský
  • 3,089
  • 1
  • 35
  • 36
0

I found a solution.

  • Integrate fontawesome-all.css
  • At the end of file Search the second @font-face and replace

    font-family: 'Font Awesome 5 Free';

With

font-family: 'Font Awesome 5 FreeR';

And replace:

.far {
  font-family: 'Font Awesome 5 Free';
  font-weight: 400; }

With

.far {
  font-family: 'Font Awesome 5 FreeR';
  font-weight: 400; }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Carmelo Valenti
  • 793
  • 1
  • 6
  • 4
0

If you are using SVG with JavaScript you need to enable this because it's disabled by default. Use

<script data-search-pseudo-elements ... >

inside your script tag.

Juri
  • 1,531
  • 2
  • 20
  • 43
0

Add the fas class.

Like:

  <i class="fas fa-solid fa-angle-left"></i>

Without the fas the icon will not be loaded

wriozumi
  • 569
  • 6
  • 6
0

If it's still not working for you you should be able to see the code line in your page source (Right Click -> select "View Page Source") where you have imported the FontAwesome stylesheet.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

If you click on that, it will open the stylesheet in a new tab. In the top part of the stylesheet you will be able to see the name of the font family.

Top part of the FontAwesome stylesheet

Then you can change the font-family only for the icons which are breaking with the new font used in the web page.

#primary-menu .fa-angle-down:before {
    font-family: 'FontAwesome', sans-serif;
    /* Changing the icons to FontAwesome font to stop breaking when the font is changed in the site */
}
Dula
  • 1,276
  • 5
  • 14
  • 23
-1

I had to set searchPseudoElements to to true to get it working in Angular5.

import fontawesome from '@fortawesome/fontawesome';
...
fontawesome.config.searchPseudoElements = true;
...
content: "\f12a";
font-family: 'Font Awesome 5 Solid';
starkm
  • 859
  • 1
  • 10
  • 21