Accepted answer

react uses the classname attribute, like the dom.

if you use the development build, and look at the console, there's a warning. you can see this on the jsfiddle.

warning: unknown dom property class. did you mean classname?


checkout react icons pretty dope and worked well.


in my case i was following the documentation for react-fontawesome package, but they aren't clear about how to call the icon when setting the icons into the library

this is was what i was doing:

app.js file

import {facoffee} from "@fortawesome/pro-light-svg-icons";
library.add(fasearch, fafilesearch, facoffee);

component file

<fontawesomeicon icon={"coffee"} />

but i was getting this error

enter image description here then i added the alias when passing the icon prop like:

<fontawesomeicon icon={["fal", "coffee"]} />

and it is working, you can find the prefix value in the icon.js file, in my case was: facoffee.js


if someone wants to do it via the official documentation. here is how i did and what i understood.

  1. install the library as mentioned on font awesome page using npm or yarn for example in general i used these
  npm i --save @fortawesome/fontawesome-svg-core
  npm install --save @fortawesome/free-solid-svg-icons
  npm install --save @fortawesome/react-fontawesome
  1. you need two import library from '@fortawesome/fontawesome-svg-core' if you want to use in general or globally, it provides the access to the icons everywhere in your project.
  import { library } from '@fortawesome/fontawesome-svg-core';
  1. to use the icons you need to import them based on the npm or yarn library you have installed. i would recommend importing this in app.js where it will be easily visible. like if i was using a free-tier shopping cart icon and it was solid you can import like below (if you are not sure if its solid, regular, etc or what library just click on the icon it will list out the different versions and based on the icon you like you can import the library for react).
  import { fashoppingcart } from '@fortawesome/free-solid-svg-icons';
  • for adding the icon name i would recommend writing the import statement and library and then precede with fa and start typing the name it will auto-recommend as soon as you type (checked in vscode) which will make it less complicated to find.
  1. you need to add the icons in the library for making it accessible globally in your project separated by a comma
library.add( fachecksquare, faambulance, fashoppingcart);
  1. after which you can import the following component
import { fontawesomeicon } from '@fortawesome/react-fontawesome';

and use it like below wherever you need the icon. for the name, it's the same as listed on the style class on the fontawesome site, for the icons. eg: shopping cart is listed as shopping-cart

<fontawesomeicon icon="shopping-cart" />

it should work now after this.


i was experienced this case; i need the react/redux site that should be working perfectly in production.

but there was a 'strict mode'; shouldn't lunch it with these commands.

yarn global add serve
serve -s build

should working with only click the build/index.html file. when i used fontawesome with npm font-awesome, it was working in development mode but not working in the 'strict mode'.

here is my solution:

*** other different types of files(4) ***
*** i copied these files for node_module/font-awesome ***
*** after copied then can delete the font-awesome from package.json ***

in public/index.html

<link rel="stylesheet" href="%public_url%/css/font-awesome.min.css">

after all of above steps, the fontawesome works nicely!!!


personally, i found react-fontawesome to be unwieldy because of the way it requires each icon to be individually imported. if you would like to use font awesome version 5 with react without using react-fontawsome, you can do it as follows:

<link href="%public_url%/fontawesome/css/all.css" rel="stylesheet">

you can now use font awesome icons in the usual way:

<i classname="fas fa-globe-europe"></i>


as 'praveen m p' said you can install font-awesome as a package. if you have yarn you can run:

 yarn add font-awesome

if you don't have yarn do as praveen said and do:

npm install --save font-awesome

this will add the package to your projects dependencies and install the package in your node_modules folder. in your app.js file add

import 'font-awesome/css/font-awesome.min.css'


alexander's answer from above really helped me out!

i was trying to get social accounts icons in the footer of my app i created with reactjs so that i could easily add a hover state to them while also having them link my social accounts. this is what i ended up having to do:

$ npm i --save @fortawesome/fontawesome-free-brands

then at the top of my footer component i included this:

import react from 'react';
import './styles/footer.css';
import fontawesomeicon from '@fortawesome/react-fontawesome';
import {fatwitter, falinkedin, fagithub} from '@fortawesome/fontawesome-free-brands';

my component then looked like this:

<a href=''>
  <fontawesomeicon classname ='font-awesome' icon={fagithub} />

worked like a charm.


you need to install the package first.

npm install --save react-fontawesome


npm i --save @fortawesome/react-fontawesome

don't forget to use classname instead of class.

later on you need to import them in the file where you wanna use them.

import 'font-awesome/css/font-awesome.min.css'


import fontawesomeicon from '@fortawesome/react-fontawesome'


after struggling with this for a while i came up with this procedure (based on font awesome's documentation here):

as stated, you'll have to install fontawesome, react-fontawesome and fontawesome icons library:

npm i --save @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/react-fontawesome

and then import everything to your react app:

import { library } from '@fortawesome/fontawesome-svg-core'
import { fontawesomeicon } from '@fortawesome/react-fontawesome'
import { fastroopwafel } from '@fortawesome/free-solid-svg-icons'


here comes the tricky part:

to change or add icons, you'll have to find the available icons in your node modules library, i.e.


each icon has two relevant files: .js and .d.ts, and the file name indicates the import phrase (pretty obvious...), so adding angry, gem and check-mark icons looks like this:

import { fastroopwafel, faangry, fagem, facheckcircle } from '@fortawesome/free-solid-svg-icons'

library.add(fastroopwafel, faangry, fagem, facheckcircle)

to use the icons in your react js code, use:

<fontawesomeicon icon=icon_name/>

the icon name can be found in the relevant icon's .js file:

e.g. for facheckcircle look inside facheckcircle.js for 'iconname' variable:

var iconname = 'check-circle'; 

and the react code should look like this:

<fontawesomeicon icon=check-circle/> 



in case you are looking to include the font awesome library without having to do module imports and npm installs, put this in the head section of your react index.html page:

public/index.html (in head section)

<link rel="stylesheet" href=""/>

then in your component (such as app.js) just use standard font awesome class convention. just remember to use classname instead of class:

<button classname='btn'><i classname='fa fa-home'></i></button>


npm install --save font-awesome

import 'font-awesome/css/font-awesome.min.css';


<i classname="fa fa-shopping-cart" style={{fontsize:24}}></i>  
        <span classname="badge badge-danger" style={{position:"absolute", right:5, top:5}}>number of</span>


the simplest solution is:


npm install --save @fortawesome/fontawesome-svg-core
npm install --save @fortawesome/free-solid-svg-icons
npm install --save @fortawesome/react-fontawesome


import { fontawesomeicon } from '@fortawesome/react-fontawesome';
import { fathumbsup } from '@fortawesome/free-solid-svg-icons';


<fontawesomeicon icon={ fathumbsup }/>


npm install --save-dev @fortawesome/fontawesome-free

in index.js

import '@fortawesome/fontawesome-free/css/all.min.css';

then use icons like below :

import react, { component } from "react";

class like extends component {
  state = {};
  render() {
    return <i classname="fas fa-heart"></i>;

export default like;


you can also use the react-fontawesome icon library. here's the link: react-fontawesome

from the npm page, just install via npm:

npm install --save react-fontawesome

require the module:

var fontawesome = require('react-fontawesome');

and finally, use the <fontawesome /> component and pass in attributes to specify icon and styling:

var mycomponent = react.createclass({
  render: function () {
    return (
        style={{ textshadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}

don't forget to add the font-awesome css to index.html:

<link rel="stylesheet" href="">


install fontawesome & react-fontawesome

$ npm i --save @fortawesome/fontawesome
$ npm i --save @fortawesome/react-fontawesome
$ npm i --save @fortawesome/fontawesome-free-solid
$ npm i --save @fortawesome/fontawesome-free-regular
$ npm i --save @fortawesome/fontawesome-svg-core

then in your component

import react, { component } from 'react';
import { fontawesomeicon } from '@fortawesome/react-fontawesome'
import { fachecksquare, facoffee } from '@fortawesome/fontawesome-free-solid'
import './app.css';

class app extends component {
  render() {
    return (
      <div classname="app">
          <fontawesomeicon icon={facoffee} />

export default app;


if you are new to react js and using create-react-app cli command to create the application, then run the following npm command to include the latest version of font-awesome.

npm install --save font-awesome

import font-awesome to your index.js file. just add below line to your index.js file

import '../node_modules/font-awesome/css/font-awesome.min.css'; 


import 'font-awesome/css/font-awesome.min.css';

don't forget to use classname as attribute

 render: function() {
    return <div><i classname="fa fa-spinner fa-spin">no spinner but why</i></div>;

Related Query

More Query from same tag