I can't colorize the Font Awesome 5 icons using these codes. I tried fill
css property for setting color but it didn't work.
HTML Code:
<div class="container mt200 icons">
<div class="col-md-3">
<div class="bggray2 text-center">
<i class="fas fa-microphone fa-5x"></i>
<div class="title">LOREM</div>
<div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.</div>
</div>
</div>
<div class="col-md-3">
<div class="bggray2 text-center">
<i class="far fa-edit fa-5x"></i>
<div class="title">LOREM</div>
<div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.
</div>
</div>
</div>
</div>
CSS Code:
.icons i {
color: #2759AE;
}
If you're using the svg-with-js version of Font Awesome 5 it takes everything in the
<i></i>
and preprocesses it into an<svg>
. It specifies that the path hasfill="currentColor"
So, you have to setcurrentColor
to the colour you want somehow. One option is:The official docs recommend inline style:
Or, set
currentColor
in one of the outer elements. For example:And to move it to the CSS file, you could:
Regular way: as suggested on documentation:
Similarly you can use style tag inside your i tag:
Other way: If you want to target all icons at once using normal css-fontawesome and not the SVG one you have this option as well:
We can add css for color using below class to below classes.
What's changed with 5.x:
The versions < 5.x were using basic
fa fa-icon-name
classes to apply icon oni
tag. With 5.x FontAwesome has modularized the classes a little bit so we do not havefa
now instead we have separate class for solid, regular and brand icons. example:Solid Style (fas) -
<i class="fas fa-clock"></i>
Regular Style (far) -
<i class="far fa-clock"></i>
Light Style (fal) -
<i class="fal fa-clock"></i>
Brand Style (fab) -
<i class="fab fa-clock"></i>
clock is used as an example, use icon-name instead.
Font Awesome 5 uses
svg
for icons andpath
inside are set withfill:currentColor
so simply change color ofsvg
:As you can see in the code, the
i
are replaced withsvg
when you load the JS version:You can apply color to
i
in case you are using the CSS version.So to make sure it will work in all the cases simply use both selector:
If you are using Bootstrap 4 you can use and of the text-'color' settings in the parent of the tag.