Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of icons in Font Awesome 5?

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;
}
like image 819
Ed Joe Avatar asked Feb 04 '18 13:02

Ed Joe


People also ask

Can you change Font Awesome icon color?

Once you decided the icons on which you want to change the color, then go to “Appearance > Customizer > Additional CSS” and paste your CSS code. Once you added your CSS code inside the box, click on the blue-colored “Publish” button showing on the top left corner.

How do I add color to Font Awesome icons?

There is a really simple way to change the colour of Font Awesome icons. You can change the hex code to your preference. NOTE: The text colour will change the icon colour as well unless there is a style="color:#00cc6a" within the i tag.

How do I change the color of an icon?

Select the element you want to recolor by simply clicking on it. Tip: If you want to change the color of the whole icon, you can quickly select all elements with a “Command + A” (for Mac) or “Ctrl + A” (for Windows) keyboard shortcut. Step 3 — Click on the Color Picker tool in the left-hand panel.

Can I modify Font Awesome icons?

1- Go to http://fontawesome.io/ Download the zip and extract-it for example in your Desktop. 2- Go to http://fontastic.me/ use your email to create an account. Once you have been logged-in click on the header option: Add More Icons. Select the SVG of font-awesome located in your extracted zip inside fonts.


2 Answers

Font Awesome 5 uses svg for icons and path inside are set with fill:currentColor so simply change color of svg:

.icons svg {
 color:#2759AE;
}
<script defer src="https://use.fontawesome.com/releases/v5.5.0/js/all.js"></script>
<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>

As you can see in the code, the i are replaced with svg when you load the JS version:

enter image description here


You can apply color to i in case you are using the CSS version.

.icons i {
 color:#2759AE;
}
<link href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" rel="stylesheet"><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>

So to make sure it will work in all the cases simply use both selector:

.icons i,
.icons svg {
   color: #2759AE;
}
like image 120
Temani Afif Avatar answered Sep 20 '22 08:09

Temani Afif


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 has fill="currentColor" So, you have to set currentColor to the colour you want somehow. One option is:

svg {color: blue;}

The official docs recommend inline style:

<i class="far fa-edit fa-5x" style="color:blue"></i>

Or, set currentColor in one of the outer elements. For example:

<div class="bggray2 text-center" style="color: blue;">
  <i class="far fa-edit fa-5x"></i>
</div>

And to move it to the CSS file, you could:

div .bggray2 {
    color: blue;
}
like image 41
duncandoo Avatar answered Sep 18 '22 08:09

duncandoo