336

I have to wrap my icon within an <a> tag for some reason.
Is there any possible way to change the color of a font-awesome icon to black?
or is it impossible as long as it wrapped within an <a> tag? Font awesome is supposed to be font not image, right?

enter image description here

<a href="/users/edit"><i class="icon-cog"></i> Edit profile</a>
TylerH
  • 20,799
  • 66
  • 75
  • 101
HUSTEN
  • 5,117
  • 4
  • 24
  • 38
  • 2
    possible duplicate of [How to style icon color, size, and shadow of Font Awesome Icons](http://stackoverflow.com/questions/12272372/how-to-style-icon-color-size-and-shadow-of-font-awesome-icons) – James Donnelly Jan 19 '14 at 10:40

23 Answers23

428

This worked for me:

.icon-cog {
  color: black;
}

For versions of Font Awesome above 4.7.0, it looks this:

.fa-cog {
  color: black;
}
Evan Hahn
  • 12,147
  • 9
  • 41
  • 59
  • @Evans Thanks but the problem is I sometime put on the table cell which is black colored. Your css forced to change it into black also:( – HUSTEN Jan 23 '13 at 07:57
  • 3
    You can add the following: .icon-cog.icon-white { color: white; } – Evan Hahn Jan 24 '13 at 20:59
  • 4
    Just came across this - I found that adding a class of 'fa' to all icons and then putting `.fa {color: green;}` did the trick. You can then do `.fa.icon-white {color: white;}` to get the same effect as you want above. – ClarkeyBoy Jan 02 '15 at 07:52
  • Is it possible to change `background-color` – vamsikrishnamannem Mar 06 '15 at 09:06
  • 1
    @vamsikrishnamannem Yup. You can add `background-color: #112233` to the CSS. Check out [this code](http://jsfiddle.net/qty0m3u0/) for an example. – Evan Hahn Mar 06 '15 at 15:42
64

HTML:

    <i class="icon-cog blackiconcolor">

css :

    .blackiconcolor {color:black;}

you can also add extra class to the button icon...

J.B.
  • 675
  • 5
  • 3
  • 1
    This is a nice, neat solution. I prefer to name classes with an fa prefix like fa-black or fa-blue just to make it clear I'm applying them to font awesome icons. – DavidHyogo Dec 04 '18 at 04:03
60

You can specify the color in the style attribute:

<a href="/users/edit"><i class="icon-cog" style="color:black"></i> Edit profile</a>
dandrews
  • 2,995
  • 1
  • 20
  • 22
13

Try this:

<i class="icon-cog text-red">
<i class="icon-cog text-blue">
<i class="icon-cog text-yellow">
Frank van Wijk
  • 3,234
  • 20
  • 41
Rahul Tathod
  • 348
  • 5
  • 12
12

To change the font awesome icons color for your entire project use this in your css

.fa {
  color : red;
}
ChAnDu353
  • 541
  • 7
  • 11
  • This is nice but changes all the icons in my project. I created classes like .fa-black {color: #000;}. I then added the fa-black classes to the icons where I wanted a different colour. – DavidHyogo Dec 04 '18 at 04:02
9

If you don't want to alter the CSS file, this is what works for me. In HTML, add style with color:

<i class="fa fa-cog" style="color:#fff;"></i>
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
7

Is there any possible way to change the color of a font-awesome icon to black?

Yes, there is. See the snipped bellow

<!-- Assuming that you don't have, this needs to be in your HTML file (usually the header) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Here is what you need to use -->
<a href="/users/edit" class="fa fa-cog" style="color:black"> Edit Profile</a>

Font awesome is supposed to be font not image, right?

Yes, it is a font. Therefore, you are able to scale it to any size without losing quality.

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
6

To hit only cog-icons in that kind of button, you can give the button a class, and set the color for the icon only when inside the button.

HTML:

<a class="my-nice-button" href="/users/edit">
    <i class="icon-cog"></i>
    Edit profile
</a>

CSS:

.my-nice-button>i { color: black; }

This will make any icon that is a direct descendant of your button black.

Adrian Schmidt
  • 1,886
  • 22
  • 35
5

For me the only thing that worked is inline css + overriding

<i class="fas fa-ellipsis-v fa-2x" style="color:red !important"></i>
Crasher
  • 2,211
  • 2
  • 18
  • 17
4

With reference to @ClarkeyBoy answer, below code works fine, if using latest version of Font-Awesome icons or if you using fa classes

.fa.icon-white {
    color: white;
}

And, then add icon-white to existing class

Sategroup
  • 955
  • 13
  • 29
3

just give and text style whatever you want like :D HTML:

<a href="javascript:;" class="fa fa-trash" style="color:#d9534f;">
   <span style="color:black;">Text Name</span>
</a>
Styx
  • 9,863
  • 8
  • 43
  • 53
2
.fa-search{
    color:#fff;
 }

you write that code in css and it would change the color to white or any color you want, you specify it

Stanjhae
  • 255
  • 2
  • 7
2

You can change the Font Awesome's icon color with the bootstrap class

use

text-color

example

text-white
Afeesudheen
  • 936
  • 2
  • 12
  • 21
2

Sometimes changing the colour in the external css file doesn't work. You can add inline css property in the icon tag and that will work.

For example

<i class="fa-solid fa-keyboard" style="color: grey;"></i>
1

just give it the style whatever you want like

style="color: white;font-size: 20px;"
Buddy
  • 10,874
  • 5
  • 41
  • 58
Rahul Tathod
  • 348
  • 5
  • 12
1

You can change the color of a fontawesome icon by changing its foreground color using the css color property. The following are examples:

<i class="fa fa-cog" style="color:white">

This supports svgs also

<style>
.fa-cog{
color:white;
}
</style>

<style>
.parent svg, .parent i{
color:white
}
</style>

<div class="parent">
  <i class="fa fa-cog" style="color:white">
</div>

Mohammed Shareef C
  • 3,829
  • 25
  • 35
1

Write this code in the same line, this change the icon color:

<li class="fa fa-id-card-o" style="color:white" aria-hidden="true">
Tasos K.
  • 7,979
  • 7
  • 39
  • 63
1

Use color property to change the color of your target element as follow :

.icon-cog { // selector of your element
    color: black;
}

Or in the newest version of font-awesome , you can choose among filled or not filled icons

mohamed ibrahim
  • 567
  • 4
  • 12
0

If you want to change the color of a specific icon, you can use something like this:

.fa-stop {
    color:red;
}
Ahmad
  • 8,811
  • 11
  • 76
  • 141
0

It might a little bit tricky to change the color of font-awesome icons. The simpler method is to add your own class name inside the font-awesome defined classes like this:

.

And target your custom_defined__class_name in your CSS to change the color to whatever you like.

Pepe
  • 137
  • 1
  • 3
0

Open the svg file in vs code or something

change the line

path fill="gray" to what ever color you want! in my case i change it to gray!

Rasla
  • 91
  • 1
  • 4
0

I added a style, then color of your choice and make sure to make it bold

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 13 '23 at 11:59
-8

HTML:

<i class="icon-cog blackiconcolor">

css :

 .blackiconcolor {color:black;}

Using class will give you a free binding property which you can apply on any tag you require.

Re Captcha
  • 3,125
  • 2
  • 22
  • 34
ameya rote
  • 1,116
  • 1
  • 9
  • 13
  • 4
    -1 Font Awesome icons are text, hence the name. They should be colored using css like any other text, not using vendor-specific tricks. Also, since they are text, they are already black-and-white (or mono-color). – Adrian Schmidt Sep 06 '13 at 15:34
  • 2
    @AdrianSchmidt Above stated answer is for converting an image to black, I didn't mean to change the font color with this, I hope you are getting me .. – ameya rote Sep 08 '13 at 13:13
  • 2
    I understand. The answer is still incorrect in regard to the question though. Font Awesome icons are not images, they are text. – Adrian Schmidt Sep 09 '13 at 09:14