DEV Community

Cover image for How To Use Font Awesome Icons in HTML
Asif Zubayer Palak
Asif Zubayer Palak

Posted on

8 2

How To Use Font Awesome Icons in HTML

Icons have become a crucial element in Web Development and adding the appropriate icons to your Website could make or break the design.
Font Awesome is an icon library that you can implement into your website straight from their website.

How to use Font Awesome Icons?


1. CDN Method

Step 1

Locate the link to font-awesome CDN by going to this site.

Step 2

Press on </> button next to the link that ends with all.min.css
Which will copy something like this onto your clipboard



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-XXXXX+y+XXXXX/XXXX==" crossorigin="anonymous" referrerpolicy="no-referrer" />


Enter fullscreen mode Exit fullscreen mode

Step 3

Go to your .html file where you're designing your webpage and paste the copied code within the <head> tag.
font-awesome CDN

Step 4

Find your desired icons from fontawesome.com or by directly going here

Step 5

Click on the icon to show its panel, which would look something like this:

Font-awesome_icon_panel
Step 6
Click on the code snippet to copy it and paste it on the desired location of your webpage.
Icon added


2. Downloading the Icon Pack

Step 1

Go to the download section of fontawesome.com and click on icon pack of your choice. I'll be using "Free for Web" for this tutorial.

Step 2

A .zip file will be downloaded, which you have to unzip and place it in the same folder as your website.

Step 3

Use the link tag in the <head> tag and locate the css file containing the icon data.
The directory would look something like this:
/fontawesome-free-x.x.x-web/css/all.css

Step 4

Find your desired icons from fontawesome.com or by directly going here

Step 5

Click on the icon to show its panel, which would look something like this:

Font-awesome_icon_panel
Step 6
Click on the code snippet to copy it and paste it on the desired location of your webpage.
Icon added

Troubleshooting

In case you notice square boxes in the places where you put the icons, there are two probable reasons (as far as I know).

One is due to the font family set onto that element or its parent element.
Since font-awesome icons are treated as fonts, declaring a different font family would override it and the font-awesome icon cannot be found.

box issue 1

Another reason could be the class declaration issue. For example, in
<i class="fa-solid fa-circle-info"></i>
no class of fa-solid may be found in the CDN.
In that case, you can remove the -solid to use the default version of the icon.
The code snippet would look something like:
<i class="fa fa-circle-info"></i>

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️