Here we will learn how to use font awesome icons in html page with example, change style and size of font awesome icons, fixed width font awesome icons example, list icons in font awesome, bordered and pulled icons in font awesome, animation icons in font awesome, rotate and flip a font awesome icons with example and stacked icons in font awesome with example.
Font Awesome is an iconic font and css toolkit. Font Awesome provides scalable vector icons that can be easily customizable in size, color, drop shadow, and anything that can be done using CSS.
To setup Font Awesome icons we don’t need any script files just by adding single line of code to our website we can use all Font Awesome icons.
To use Font Awesome icons in web site please copy paste following line of code into the <head>
section of your website.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
Once we add above CSS file to our website we are ready to use Font Awesome icons in our site by adding <i>
tag
Font Awesome icons are designed to use with inline elements <i>
or <span>
tags. We can place Font Awesome icons in website by prefixing fa and icon’s name to <i>
or <span>
tag that would be like as shown below
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-desktop"></i>
<i class="fa fa-diamond"></i>
<i class="fa fa-key"></i>
</body>
</html>
If we observe above code we added three icons in code. Now we will run and see the output.
Following is the result of using font awesome basic icons.
Now will check how to change style of font awesome icons using css styles.
As discussed earlier we can change the style of icons like increasing font size, color, etc. using CSS properties that would be like as shown below
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-desktop"></i>
<i class="fa fa-desktop" style="font-size:30px;"></i>
<i class="fa fa-desktop" style="font-size:50px;color:blue"></i>
</body>
</html>
If we observe above code we are changing size of icons and color of icons.
Following is result of changing style of font awesome icons style.
If we change the font-size of the icon's container automatically the icon gets bigger. Same thing goes for color, shadow, and anything else that get inherited using CSS.
By using fa-lg
(33% increase), fa-2x
, fa-3x
, fa-4x
, or fa-5x
classes we can increase size of icons relative to container. Following example shows how to use these classes to increase size of icons.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-desktop fa-lg"></i>
<i class="fa fa-desktop fa-2x"></i>
<i class="fa fa-desktop fa-3x"></i>
<i class="fa fa-desktop fa-4x"></i>
<i class="fa fa-desktop fa-5x"></i>
</body>
</html>
In above example we are changing size of icons using fa-2x
, fa-3x
, fa-4x
, or fa-5x
classes.
Following is the result of changing size of font awesome icons.
Note: In case if your icons are getting chopped off on top and bottom, please make sure you have sufficient line-height.
By using fa-fw
class we can set fixed width to icons. This will be useful when different icon widths throw off alignment in navigation menus and group lists. Following example shows how to use fixed width class in icons.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<div class="list-group">
<a class="list-group-item" href="#"><i class="fa fa-home fa-fw"></i> Home</a>
<a class="list-group-item" href="#"><i class="fa fa-book fa-fw"></i> Library</a>
<a class="list-group-item" href="#"><i class="fa fa-pencil fa-fw"></i> Applications</a>
<a class="list-group-item" href="#"><i class="fa fa-cog fa-fw"></i> Settings</a>
</div>
</body>
</html>
In above code we used fa-fw
class to set fixed width for icons. Now will run and see the output.
Following is the result of font awesome fixed width icons example.
By using fa-ul
and fa-li
classes we can easily replace default bullets in unordered list. Following example will show how to use these classes to replace default bullets in unordered list.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<ul class="fa-ul">
<li><i class="fa-li fa fa-check-square"></i>Unordered List icons</li>
<li><i class="fa-li fa fa-spinner fa-spin"></i>Unordered List icons</li>
<li><i class="fa-li fa fa-square"></i>Unordered List icons</li>
</ul>
</body>
</html>
In above example we used fa-ul
and fa-li
classes to make icons as list.
Following is the result of font awesome list icons example.
By using fa-border
and fa-pull-right
or fa-pull-left
classes we can pull quotes or article icons. Following example show how to use these classes to pull quotes.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-quote-left fa-3x fa-pull-left fa-border"></i>
...Welcome to tutlane.com website it's complete technical tutorial site which we launced recently our target is to reach as many as we can... and we have confidence to become no. 1 technical site which provide complete tutorials for all software related technologies
</body>
</html>
If you observe above example we used fa-border
and fa-pull-left
classes to pull icons.
Following is the result of font awesome bordered & pulled icons example.
By using fa-spin
class we can spin or rotate any icon and using fa-pulse
class we can make any icon rotate with 8 steps. Following example shows how to use these classes to rotate icons.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-spinner fa-spin"></i>
<i class="fa fa-circle-o-notch fa-spin"></i>
<i class="fa fa-refresh fa-spin"></i>
<i class="fa fa-cog fa-spin"></i>
<i class="fa fa-spinner fa-pulse"></i>
</body>
</html>
In above example we used fa-spin
and fa-pulse
classes to apply animation effect to font awesome icons.
Following is the result of font awesome animation icons example.
Note: CSS3 animations will not support in IE8 & IE9
By using fa-rotate-*
and fa-flip-*
classes we can rotate or flip icons arbitrarily. Following example shows how to use these classes to flip icons.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<i class="fa fa-hand-paper-o"></i> normal<br>
<i class="fa fa-hand-paper-o fa-rotate-90"></i> rotate-90<br>
<i class="fa fa-hand-paper-o fa-rotate-180"></i> rotate-180<br>
<i class="fa fa-hand-paper-o fa-rotate-270"></i> rotate-270<br>
<i class="fa fa-hand-paper-o fa-flip-horizontal"></i> flip-horizontal<br>
<i class="fa fa-hand-paper-o fa-flip-vertical"></i> flip-vertical
</body>
</html>
In above example we are rotating font awesome icons using fa-rotate-*
and fa-flip-*
classes.
Following is the result of font awesome rotate and flip icons example.
To stack multiple icons, we need to use fa-stack
class on the parent, the fa-stack-1x
for the regularly sized icon, and fa-stack-2x
for the larger icon and fa-inverse
can be used as an alternative icon color. You can even throw larger icon classes on the parent to get further control of sizing.
Following example shows how to use these classes for icons.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title></title>
</head>
<body>
<span class="fa-stack fa-lg">
<i class="fa fa-square-o fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x"></i>
</span>
fa-twitter on fa-square-o<br>
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-flag fa-stack-1x fa-inverse"></i>
</span>
fa-flag (inverse) on fa-circle<br>
<span class="fa-stack fa-lg">
<i class="fa fa-camera-retro fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x text-danger" style="color:red;"></i>
</span>
fa-ban on fa-camera
</body>
</html>
In above example we used classes to make font awesome icons as stacked.
Following is the result of font awesome stacked icons example.
The font awesome icons will work great with bootstrap components. So we can use these icons where we required along with bootstrap components.