How to add font awesome to Blazor client (razor component) app?

Sorush picture Sorush · Dec 5, 2019 · Viewed 9.7k times · Source

I created a blazor webassembly hosted template dot net core 3.1. Then right clicked on project.Client/wwwroot/css folder and click on add client side library. Then selected font-awesome library in installed it. I added below line to index.html head.

 <link href="css/font-awesome/css/fontawesome.css" rel="stylesheet"/>

I have libman.json of

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "[email protected]",
      "destination": "wwwroot/css/font-awesome/"
    }
  ]
}

I added just below line to default blazor template page counter (razor component). The intelisense finds the font:

@page "/counter"

<h1>Counter</h1>

<span class="fa fa-save"></span>

@code {}

but I only see a square

enter image description here

Answer

Henk Holterman picture Henk Holterman · Dec 5, 2019

You also need to include the JavaScript.

<link rel="stylesheet" href="css/font-awesome/css/fontawesome.min.css" />
<script src="css/font-awesome/js/all.min.js"></script>

You can put the <script> tag below the other one at the bottom of the file but I doubt that you'll notice any speed difference.

From a now deleted comment:

The JS is just one option (the preferred option), but CSS only is still an option as well. Also, you don't use both. It's either CSS or JS

In Blazor I could only get the JS version to work. CSS only didn't work (the file was 200-OK).