How to style icon color, size, and shadow of FontAwesome Icons
Asked Answered
M

25

421

How could I style the color, size and shadow of icons from FontAwesome's Icons?

For example, FontAwesome's site will show some icons in white and some in red but won't show the CSS for how to style them that way ...

Buttons and links of different colours, with both red, white and black icons next to them

Monosepalous answered 4/9, 2012 at 22:44 Comment(0)
C
547

Given that they're simply fonts, then you should be able to style them as fonts:

#elementID {
    color: #fff;
    text-shadow: 1px 1px 1px #ccc;
    font-size: 1.5em;
}
Candless answered 4/9, 2012 at 22:50 Comment(3)
@David Thomas: That's a good solution. Thank you for posting that. However, I am STILL baffled why font-awesome sometimes shows icons in white and sometimes in black. WHAT IS THE TRICK? As GirlCanCode2 pointed out, the examples on the FA web site show both black and white icons & text . . . examining the elements in Firebug, however, the CSS for specific icons (e.g., icon-info) gets [over]written to be white. Is that really what we have to do? No icon-white option as in bootstrap.css?Rerun
for changing the color, check this in SO, hope helps someoneLaplante
@Rerun I know this is old and you might have learned this by now but for others as well that have the question you might want to look into specificity here and also here. The other thing to know is the CSS cascade; for example styles and stylesheets that come after others are applied instead unless their style rule selectors are less specific (as in specificity). So, my favorite practice is to atleast match specifity and put style after to override.Cumber
B
203

You can also just add style inline:

<i class="icon-ok-sign" style="color:green"></i>

<i class="icon-warning-sign" style="color:red"></i>
Broadminded answered 11/3, 2013 at 19:3 Comment(4)
To me it makes no sense to place a simple color css directive into its own class and bundle it with your css assets. What will you do? class='icon-ok-sign my-red-class' ? or class='icon-ok-sign-red' ? That makes it less readable and adds a useless level of complexity.Voltammeter
Using <i> tag for icons also isn't the best of practices. Why nitpick then?Brutalize
#id can be overwritten by other styles more easily than inline styles can, without needing "!important" - so it's still less bad. - On the other hand, I see no reason not to make it .class-name --- submitted an edit for the top rated question. --- using i for icons is fine, since i unlike em has no semantic meaning. So quite apples to oranges imho.Belittle
Inline comments are bad practice. this is a bad suggestionTokyo
G
141

If you are using Bootstrap at the same time, you can use:

<i class="fa fa-check-circle-o fa-5x text-success" ></i>

Otherwise:

<i class="fa fa-check-circle-o fa-5x" style="color:green"></i>
Gassman answered 21/10, 2014 at 18:5 Comment(1)
subtle but important: the text-success is the text color, not the color of the button face for btn-success. So if you are wanting an icon to look like a "flat button", then text-success will be slightly different. I find this is most apparent in text-warning, since it is an ugly yellow as opposed to a very visible orangeTugman
T
48

Looks like the FontAwesome icon color responds to text-info, text-error, etc.

<div style="font-size: 44px;">
   <i class="icon-umbrella icon-large text-error"></i>
</div>
Theall answered 27/9, 2012 at 1:41 Comment(1)
For Bootstrap, <i class="fa fa-warning text-danger"></i>Divvy
I
19

inyour.css file:

    *.icon-white {color: white}
    *.icon-silver {color: silver}

inyour.html file:

    <a><i class="icon-book icon-white"></i> Book</a>
    <a><i class="icon-ok-sign icon-silver"></i> OK</a>
Intimist answered 12/9, 2013 at 16:47 Comment(0)
I
19
  • For Size: fa-lg, fa-2x, fa-3x, fa-4x, fa-5x
  • For Color: <i class="fa fa-link fa-lg" aria-hidden="true"style="color:indianred"></i>
  • For Shadow: .fa-linkedin-square{text-shadow: 3px 6px #272634;}
Ize answered 25/7, 2018 at 21:45 Comment(0)
P
14

There is a really simple way to change the colour of Font Awesome icons.

<!-- Font Awesome insert code -->
<script src="https://use.fontawesome.com/49b98aaeb5.js"></script>
<!-- End -->
<i class="fa fa-thumbs-up fa-5x" aria-hidden="true" style="color:#00cc6a"></i>
<i class="fa fa-thumbs-up fa-4x" aria-hidden="true" style="color:#00cc6a"></i>
<i class="fa fa-thumbs-up fa-3x" aria-hidden="true" style="color:#00cc6a"></i>
<i class="fa fa-thumbs-up fa-2x" aria-hidden="true" style="color:#00cc6a"></i>
<i class="fa fa-thumbs-up" aria-hidden="true" style="color:#00cc6a"></i>

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.

Photosynthesis answered 16/4, 2017 at 5:11 Comment(0)
V
10

Using FA 4.4.0 adding

.text-danger
    color: #d9534f

to the document css and then using

 <i class="fa fa-ban text-danger"></i>

changes the color to red. You can set your own for any color.

Verbal answered 12/9, 2015 at 22:33 Comment(0)
C
9

http://fortawesome.github.io/Font-Awesome/examples/

<i class="icon-thumbs-up icon-3x main-color"></i>

Here I have defined a global style in my CSS where main-color is a class, in my case it is a light blue hue. I find that using inline styles on Icons with Font Awesome works well, esp in the case when you name your colors semantically, i.e. nav-color if you want a separate color for that, etc.

In this example on their website, and how I have written in my example as well, the newest version of Font Awesome has changed the syntax slightly of adjusting the size.Before it used to be:

icon-xxlarge

where now I have to use:

icon-3x

Of course, this all depends on what version of Font Awesome you have installed on your environment. Hope this helps.

Cosec answered 9/7, 2013 at 13:25 Comment(0)
D
9

Just target font-awesome predefined class name

in ex:

HTML

<i class="fa fa-facebook"></i> 

CSS

i.fa {
    color: red;
    font-size: 30px;
}
Disequilibrium answered 2/2, 2018 at 16:41 Comment(0)
G
8

In FontAwesome 4.0, the classes change to 'fa-2x', 'fa-3x'.

Galore answered 16/12, 2013 at 18:59 Comment(0)
S
8

Simply you can define a class in your css file and cascade it into html file like

<i class="fa fa-plus fa-lg green"></i> 

now write down in css

.green{ color:green}
Sarthe answered 10/1, 2017 at 6:33 Comment(0)
G
6

Please refer to the link http://www.w3schools.com/icons/fontawesome_icons_intro.asp

<i class="fa fa-car"></i>
<i class="fa fa-car" style="font-size:48px;"></i>
<i class="fa fa-car" style="font-size:60px;color:red;"></i>

<i class="fa fa-car fa-lg"></i>
<i class="fa fa-car fa-2x"></i>
<i class="fa fa-car fa-3x"></i>
<i class="fa fa-car fa-4x"></i>
<i class="fa fa-car fa-5x"></i>
Giorgia answered 28/10, 2016 at 6:50 Comment(0)
H
5

I had the same problem when I tried to use the icons directly from BootstrapCDN (the easiest way). Then I downloaded the CSS file and copied it to my site's CSS folder the CSS file (Described under the 'easy way' in font awesome documentation), and everything started working as they should.

Huss answered 26/7, 2013 at 2:21 Comment(0)
K
4

Credit: Can I change the color of Font Awesome's icon color?

(this answer builds on that answer)

(for the bookmark icon, for example:)

inyour.css file:

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

inyour.html file:

<div class="icon-bookmark icon-white"></div>
Krahmer answered 4/7, 2013 at 13:54 Comment(0)
A
4

Wrap the i tag in p or span, then you can use bootstrap css class

<p class="text-success"><i class="fa fa-check"></i></p>
Allynallys answered 19/4, 2016 at 3:6 Comment(0)
D
2

For Font Awesome 5 SVG version, use

filter: drop-shadow(0 0 3px rgba(0,0,0,0.7));
Dibasic answered 9/4, 2018 at 19:53 Comment(0)
E
1

As it has been pointed out, font awesome icons are text, consequently you style it using the appropriate CSS attributes. For example:

.fa-twitter-square {
    font-size: 15px;
    color: red;
}

If, as it happens quite a bit to me, the icon size doesn't change at all, add "!important" to the font-size attribute.

.fa-twitter-square {
    font-size: 15px !important;
    color: red;
}
Execratory answered 9/8, 2017 at 17:20 Comment(1)
Thank you @gmartinss. I tried <fa icon="chess-board"/> &nbsp; and .fa-chess-board { size: xs !important; color: red !important; background-color: rgba(255, 0, 255, 0.228) !important; fill: rgba(43, 255, 0, 0.338) !important; } between the <style> tags. While the background color did change to light purple, fill / color & size were unchanged. Size was also unaffected when I changed to size: 5px !important;Ugh!Stuffy
B
1

For Sizing Icons

Both our Web Fonts + CSS and SVG + JS frameworks include some basic controls for sizing icons in the context of your page’s UI.

you can use like

<i class="fas fa-camera fa-xs"></i>
<i class="fas fa-camera fa-sm"></i>
<i class="fas fa-camera fa-lg"></i>
<i class="fas fa-camera fa-2x"></i>
<i class="fas fa-camera fa-3x"></i>
<i class="fas fa-camera fa-5x"></i>
<i class="fas fa-camera fa-7x"></i>
<i class="fas fa-camera fa-10x"></i>

https://fontawesome.com/how-to-use/on-the-web/styling/sizing-icons

Bryan answered 14/6, 2019 at 20:36 Comment(0)
G
1

This answer is updated for Rails 7 and FontAwesome 6.5.1

If you install the gem into your project, you will gain access to helper methods for using Font Awesome. This article provides more information on adding the gem to your project: https://fontawesome.com/v6/docs/web/use-with/ruby-on-rails

When using the helper method, you can embed the icon into your pages using ruby code, like so:

<%= icon('fa-solid', 'bell')  %>

To add a color straight to the ERB helper, you would add that color into the second string. For example if I wanted to pass in the color green:

<%= icon('fa-solid', 'bell green')  %>

The color will have to be created in your CSS stylesheet first though. This will also work for Tailwind or Bootstrap, but you will include their color flag instead. Since FontAwesome Icons are text, you can change them with the text-color.

Example of using tailwind to change the color of an ERB FontAwesome icon:

<%= icon('fa-solid', 'bell text-orange-500')  %>
Gamages answered 23/12, 2023 at 9:3 Comment(0)
C
0

Dynamically change the css properties of .fa-xxx icons:

<li class="nws">
<a href="#NewsModal" class="urgent" title="' + title + '" onclick=""><span class="label label-icon label-danger"><i class="fa fa-bolt"></i></span>' 
</a>
</li>
<script>
  $(document).ready(function(){
   $('li.nws').on("focusin", function(){
    $('.fa-bolt').addClass('lightning');
   });
 });
</script>

<style>
.lightning{ /*do something cool like shutter*/}
</style>
Chevaldefrise answered 29/8, 2016 at 5:2 Comment(0)
K
0
text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
Klaxon answered 13/3, 2017 at 18:55 Comment(0)
R
0

Try to simply use something like fa-lg,fa-2x,fa-3x,fa-4x,fa-5x to increase the icon size relative to their container

for eg:-

Runabout answered 13/7, 2020 at 13:8 Comment(0)
R
-1

I would not advice you to use built in font-awesome styling like the fa-5x etc; for fear they may change it and you would have to keep chainging your application code to meet up with the latest standard. You simply avoid this by giving each font-awesome class you want to style uniformly the same class say:

<i class="fa fa-facebook-square fa-sabi-social-icons" aria-hidden="true"></i>
<i class="fa fa-twitter-square fa-sabi-social-icons" aria-hidden="true"></i>
<i class="fa fa-google-plus-square fa-sabi-social-icons" aria-hidden="true"></i>

Here the class is fa-sabi-social-icons

Then in your css you can the style the fonts using the same css rules you would style a normal font with. e.g

.fa-sabi-social-icons {
     color: //your color;
     font-size: // your font-size in px, em or %;
     text-shadow: 2px 2px #FF0000;
}

That should get your font-awesome fonts styled

Rutty answered 11/12, 2017 at 16:37 Comment(0)
P
-2

Here is an example how to styling font-awesome:

.arrow i.fa {
  color: white !important;
  font-size: 2.2rem;
  opacity: .3;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="arrow d-none d-md-block">
  <i class="fa fa-angle-down"></i>
</div>

That's it.

Papoose answered 21/10, 2021 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.