DEV Community

Abhi Raj
Abhi Raj

Posted on

19

how to install and use font awesome icons in react js easily


For a video tutorial watch this ☝🏿

First make a react project and install these 4 packages



//install this core package first
npm i --save @fortawesome/fontawesome-svg-core

//install first if you want to use solid icons and
//install second if you want to use regular icons
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons

//install this react component to use fontawesome
npm i --save @fortawesome/react-fontawesome@latest



Enter fullscreen mode Exit fullscreen mode

now go to here and pick any icon you like
https://fontawesome.com/search?o=r&s=regular%2Csolid&f=sharp

suppose i like this one

Image description

as you can see it's react code is this
<FontAwesomeIcon icon="fa-sharp fa-solid fa-hippo" />

so basicallly you need the last one i.e, fa-hippo
change this to CamelCase and remove dash(-) so it will be fa-hippo to faHippo
and now you can use it like this




import "./App.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faHippo } from "@fortawesome/free-solid-svg-icons";
function App() {
  return (
    <div className="App">
      <FontAwesomeIcon icon={faHippo} />
    </div>
  );
}

export default App;


Enter fullscreen mode Exit fullscreen mode

Press the like if you enjoyed this article

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay