Open In App

ReactJS | Icons

A built-in library of icons is provided by React, by using it we can include any number of icons in our project. We just have to import module in our app.js file by mentioning library name and icon name which we want to add.

Prerequisites:  



Below all the steps are described order wise how to add icons and design them in React.

npm install react-icons --save

https://react-icons.github.io/react-icons/icons?name=gi

import { IconName } from "react-icons/";

app.js:






import React, { Component } from "react";
 
// gi is sort name of game icon.
import { GiPoliceBadge } from "react-icons/gi";
 
// The GiPoliceBadge is icon name.
class App extends Component {
    render() {
        return (
            <div>
                <GiPoliceBadge />
            </div>
        );
    }
}
export default App;

Output: 

npm start
http://localhost:3000/

app.js: To change color of Icons and size, see below code.




import React, { Component } from "react";
 
// gi is sort name of game icon.
import { GiPoliceBadge } from "react-icons/gi";
 
// The GiPoliceBadge is icon name.
class App extends Component {
    render() {
        return (
            <div>
                <GiPoliceBadge size="100px" color="green"/>
            </div>
        );
    }
}
export default App;

Output:

app.js: To add multiple icons, see below




import React, { Component } from "react";
 
// gi is sort name of game icon.
import { GiPoliceBadge } from "react-icons/gi";
import { MdAndroid } from "react-icons/md";
import { GoBroadcast } from "react-icons/go";
import { FaAmazon } from "react-icons/fa";
// The GiPoliceBadge is icon name.
class App extends Component {
    render() {
        return (
            <div>
                <GiPoliceBadge size="50px" color="green"/>
                <MdAndroid size="50px" color="yellow" />
                <GoBroadcast size="50px" color="purple"/>
                <FaAmazon size="50px" color="black" />
            </div>
        );
    }
}
export default App;

Output:


Article Tags :