Introducing Font Awesome 5 and SVG icons

After a lot of research and guessing, I was able to get the svg icons to work.

First, I opened the svgs I downloaded from FA in Illustrator and followed this How To Export SVGs For The Web From Illustrator - Colin Lord - Medium to export. I’m not sure if this step was necessary.

Then I uploaded those svgs into the theme component, copied the url and put them into the css which ended up looking like this:

.b-header a::before{
    filter: invert(90%) sepia(30%) saturate(839%) hue-rotate(336deg) brightness(101%) contrast(99%);
    display: inline-block;
    content: ' ';
    background-size: contain;
    height: 15px;
    width: 15px;
    margin-right: 8px;
    margin-top: 4px;

.b-header .nav-pills > li:nth-child(1) a::before {
    background: url(''); //home
    background-repeat: no-repeat;

.b-header .nav-pills > li:nth-child(2) a::before {
    background: url(''); //community
    background-repeat: no-repeat;

.b-header .nav-pills > li:nth-child(3) a::before {
    background: url(''); //articles
    background-repeat: no-repeat;
    margin-top: 6px;

.b-header .nav-pills > li:nth-child(4) a::before {
    background: url(''); //store
    background-repeat: no-repeat;
    margin-top: 3px;

.b-header .nav-pills > li:nth-child(5) a::before {
    background: url(''); //archive
    background-repeat: no-repeat;
    margin-top: 2px;

.b-header .nav-pills > li:nth-child(6) a::before {
    background: url(''); //info
    background-repeat: no-repeat;
    margin-top: 0px;

.b-header .nav-pills > li:nth-child(7) a::before {
    background: url(''); //contact
    background-repeat: no-repeat;

.b-header .nav-pills > li:nth-child(8) a::before {
    background: url(''); //account
    background-repeat: no-repeat;

The key to changing the color of the svg was using filter: invert(90%) sepia(30%) saturate(839%) hue-rotate(336deg) brightness(101%) contrast(99%);

You can convert hex colors to filter here:

Also the icon was tiling so I had to add background-repeat: no-repeat;

For some reason the icons were not aligning so I had to adjust the margin-top:; for each icon. I’m sure there’s a more elegant way of achieving this!


Right, using SVGs as a linked image unfortunately means you can’t control the fill color. As you discovered, CSS filters are one way to overcome this.

What was missing was the height/width attribute within the SVG file. If you open an SVG in a text editor, you’ll see this:

<svg xmlns="" aria-hidden="true" data-prefix="fas" data-icon="home" class="svg-inline--fa fa-home fa-w-18" role="img" width="25" height="25" viewBox="0 0 576 512">
  <path fill="currentColor" d="M488 312.7V456c0 13.3-10.7 24-24 24H348c-6.6 0-12-5.4-12-12V356c0-6.6-5.4-12-12-12h-72c-6.6 0-12 5.4-12 12v112c0 6.6-5.4 12-12 12H112c-13.3 0-24-10.7-24-24V312.7c0-3.6 1.6-7 4.4-9.3l188-154.8c4.4-3.6 10.8-3.6 15.3 0l188 154.8c2.7 2.3 4.3 5.7 4.3 9.3zm83.6-60.9L488 182.9V44.4c0-6.6-5.4-12-12-12h-56c-6.6 0-12 5.4-12 12V117l-89.5-73.7c-17.7-14.6-43.3-14.6-61 0L4.4 251.8c-5.1 4.2-5.8 11.8-1.6 16.9l25.5 31c4.2 5.1 11.8 5.8 16.9 1.6l235.2-193.7c4.4-3.6 10.8-3.6 15.3 0l235.2 193.7c5.1 4.2 12.7 3.5 16.9-1.6l25.5-31c4.2-5.2 3.4-12.7-1.7-16.9z"/>

If you scroll to the right a bit and look at line 1, the part I added was width="25" height="25". It looks like Font Awesome icons don’t come with dimensions defined inline (it isn’t necessary if you’re embedding SVGs directly in HTML).

If you look at the line 2, you can also see the fill definition, you can change this to a hex color.


How would I do this for a brand icon? I entered “fab fa-discord” into site settings and added this html

<svg class="fab d-icon d-icon-discord svg-icon svg-node"><use xlink:href="#discord"></use></svg>

But it does not show. I must be missing something.

1 Like

Use #fab-discord here


Do you have a fix for the old “Add icon to header”-function?

As of now I am using code very similar to the following within my header:

api.decorateWidget('header-icons:before', helper => {
    return helper.h('li', [
        helper.h('a#globe-button.icon', {
            title: 'Back to website'
        }, helper.h('i.fa.fa-globe.globe-button-icon.d-icon')),

Ofc the “i”-functionality is broken but since I am no dev myself I was wondering what to tweak in order to get the icons displayed again :slight_smile:

1 Like

Hey @LKNickname, try this out:

const { iconNode } = require("discourse-common/lib/icon-library");
api.decorateWidget("header-icons:before", helper => {
  return helper.h("li", [
        href: "",
        title: "Back to website"

Thanks @tshenry, I’ve also updated the original how-to.


Worked like a charm, thanks :slight_smile:


I’ve read all the replies here and am trying to keep this as simple as possible

This is what my html looked like before:

<a class="red" href=""><i style="margin-top: -1px;" class="fa fa-edit"></i><span>&nbsp; Courses</span></a>

I switched to this, and it didn’t work:

<a class="red" href=""><svg style="margin-top: -1px;" class="fas d-icon d-icon-edit svg-icon svg-node"><use xlink:href="#edit"></svg><span>&nbsp; Courses</span></a>

You can see the FA icons in action on my actual site, and here is the same custom global nav bar on my discourse site.

I want to get them back and keep the code as simple and consistent as possible so everything still perfectly aligns with the global nav on my WordPress site.

Would really appreciate some help!

In the *.hbs file, you can replace it with:

<a class="red" href="">{{d-icon "edit"}}<span>&nbsp; Courses</span></a>

In widgets:

+ import { iconHTML } from "discourse-common/lib/icon-library";
+ let icon_edit = iconHTML('edit');
+ ${icon_edit}

It works for us.

Much depends on where you add the icons (via plugin, admin panel …). Examples of the above we did for plugins.

1 Like

Thanks for the response @Stranik.

Something interesting is that I only changed my html for the “home” link, which is the first of my five links in the global nav bar. It didn’t work. Then about 30 minutes laters I looked at the site and it was working! So I’ve updated all of my other links to follow the same convention. Same issue… not working… but I’m wondering if some time passes and they will load as well ¯_(ツ)_/¯

While the Home icon seems to be working… for all of the links I’m getting an error…

But… back to your suggestion…

In widgets:

+ import { iconHTML } from "discourse-common/lib/icon-library";
+ let icon_edit = iconHTML('edit');
+ ${icon_edit}

If I were to go the route you suggested, where would I add all of this? :arrow_up:

The option with the plugin (widgets), the one that I gave above, does not suit you.

I think, in your case, the option suggested above in the post will work:

I tried on the test site and it worked.

I do not know how such a construction is correct, but apparently it works for me.

<svg aria-hidden="true" data-prefix="fas" width="25" height="25" data-icon="edit" role="img" xmlns="" viewBox="0 0 576 512" class="svg-inline--fa fa-edit fa-w-18"><path fill="currentColor" d="M402.6 83.2l90.2 90.2c3.8 3.8 3.8 10 0 13.8L274.4 405.6l-92.8 10.3c-12.4 1.4-22.9-9.1-21.5-21.5l10.3-92.8L388.8 83.2c3.8-3.8 10-3.8 13.8 0zm162-22.9l-48.8-48.8c-15.2-15.2-39.9-15.2-55.2 0l-35.4 35.4c-3.8 3.8-3.8 10 0 13.8l90.2 90.2c3.8 3.8 10 3.8 13.8 0l35.4-35.4c15.2-15.3 15.2-40 0-55.2zM384 346.2V448H64V128h229.8c3.2 0 6.2-1.3 8.5-3.5l40-40c7.6-7.6 2.2-20.5-8.5-20.5H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V306.2c0-10.7-12.9-16-20.5-8.5l-40 40c-2.2 2.3-3.5 5.3-3.5 8.5z" class=""></path></svg>


For the edit icon, you can use the following SVG code:

<svg class="fa d-icon d-icon-pencil svg-icon svg-node" aria-hidden="true">
  <use xlink:href="#pencil-alt"></use>

Note that you should aim to figure out how to use the JS/Handlebars helper functions in the OP, they automatically handle renamed FontAwesome icons. When using SVGs directly, you’re going to need to track down the icons yourself. As you can see in code above, the edit icon in FA5 is called pencil-alt in the <use> tag. (For other renames, refer to the FontAwesome upgrade guide.)

Also note that the class to include in the svg element is fa, not fas.


I agree with your sentiment here and am okay with a CSS only solution.

Can you tell me exactly what JS I need to put in my </head> ? And what the matching HTML element should look like?

I had a tough time interpreting the OP :disappointed: I’m pretty new to all of this

I think your best bet here is to look at how some theme components work. I would highlight these two specifically:


You can install these two components on your site, and/or inspect their code to see how they use JS to insert elements on the page.


Just reporting back a simple CSS solution that worked for me and coincides perfectly with my global navbar in wordpress:

I added the following to :

<link rel="stylesheet" href="" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">

My html in the “Header” looks like this:

    <a class="red" href=""><i style="margin-top: -1px;" class="fas fa-home fa-sm"></i><span>&nbsp; Home</span></a> 
    <a class="red" href=""><i style="margin-top: -1px;" class="fas fa-edit fa-sm"></i><span>&nbsp; Courses</span></a> 
    <a class="red" href=""><i style="margin-top: -1px;" class="fas fa-calendar-alt fa-sm"></i><span>&nbsp; Events</span></a>
    <a class="grn" href=""><i style="margin-top: -1px;" class="fas fa-comments fa-sm"></i><span>&nbsp; Community</span></a>
    <a class="grn" href=""><i style="margin-top: -1px;" class="fas fa-star fa-sm"></i><span>&nbsp; Resources</span></a>

Annnnnnd, my navbar FA icons are back!


This will make your site load both the SVG version of Font Awesome and the WebFont version, which will be a extra bytes (85kb).

Not to mention that the extra CSS (foreign to Discourse now) can break in weird ways in the future.


YOWZA! That’s not good to have all the extra bytes. Is there a way to prevent it from loading the SVG version as well? It was just so much easier to do this approach, and I just wanted my icons back up as quick as possible.

I think you need to do this the correct way rather than the “easy” way…


Wiser words have never been spoken! ツ

Thanks for the tip about the implications of the hacky approach I shared, @Falco. I’ll see if I can figure out how to do it the “correct” way when I have some time!