How To Use Material UI Icons In ReactJS Application

Introduction 

 
In this article we will learn how to use Material-UI Icons in a React application.React Material UI provide more than 1000 icons. Material UI is one of the most popular UI frameworks developed by Google.The Material UI library is designed for faster, easier and developer-friendly user interface development. Now Material-UI supported by all major browsers and platforms.
 
You can check my previous articles in which we discussed the basics of Material UI, from the below mentioned links
Prerequisites
  • Basic knowledge of React.js
  • Visual Studio Code IDE

Create ReactJS project

 
Let's first create a React application using the following command.
  1. npx create-react-app matform   
Open the newly-created project in Visual Studio Code and install Material-UI and Material-UI icons by using following commands.
 
Install Material-UI
  1. npm install @material-ui/core --save   
Install Material-UI icons
  1. npm install @material-ui/icons     
Now, right click on "src" folder and add a new component named 'MatIcon.js'. import following icons in this component.
  1. import Home from '@material-ui/icons/Home';  
  2. import  Notifications  from '@material-ui/icons';  
  3. import ContactsIcon from '@material-ui/icons/Contacts';   
 Add the following code in this component.
  1. import React, { Component } from 'react'  
  2. import Home from '@material-ui/icons/Home';  
  3. import AppBar from '@material-ui/core/AppBar';  
  4. import Toolbar from '@material-ui/core/Toolbar';  
  5. import { Notifications } from '@material-ui/icons';  
  6. import ContactsIcon from '@material-ui/icons/Contacts';  
  7. export class MatIcon extends Component {  
  8.         render() {  
  9.                 return (  
  10.                         <div>  
  11.                                 <AppBar className="mrg" position="static">  
  12.                               
  13.                                         <Toolbar>  
  14.                                         <Home/>   <Notifications/>  <ContactsIcon/>  
  15.                                         <div style={{ 'paddingLeft'"600px" }}>   Material UI Icons</div>  
  16.                           </Toolbar>  
  17.                                 </AppBar>  
  18.   
  19.                                 <Home/> Home Icon <br></br>  
  20.                                 <Notifications/> Notification Icon<br></br>  
  21.                                 <ContactsIcon/> Contact  
  22.   
  23.                         </div>  
  24.                 )  
  25.         }  
  26. }  
  27.   
  28. export default MatIcon  
Now add reference of this component in app.js file and run by using 'npm start' command,
 
How To Use Material UI Icons In ReactJS Application
Now add one more component, named 'MatIcon1.js', ,in this component we add social media icons. Add the following code in this component
  1. import React, { Component } from 'react'  
  2. import FacebookIcon from '@material-ui/icons/Facebook';  
  3. import AppBar from '@material-ui/core/AppBar';  
  4. import Toolbar from '@material-ui/core/Toolbar';  
  5. import TwitterIcon from '@material-ui/icons/Twitter';  
  6. import LinkedInIcon from '@material-ui/icons/LinkedIn';  
  7. import MailIcon from '@material-ui/icons/Mail';  
  8. import InstagramIcon from '@material-ui/icons/Instagram';  
  9. import YouTubeIcon from '@material-ui/icons/YouTube';  
  10. export class Maticon1 extends Component {  
  11.         render() {  
  12.                 return (  
  13.                         <div>  
  14.                                 <AppBar className="mrg" position="static">  
  15.                                         <Toolbar>  
  16.                                                 <div style={{ 'paddingLeft'"600px" }}>   Material UI Social media Icons</div>  
  17.                                         </Toolbar>  
  18.                                 </AppBar>  
  19.                                 <FacebookIcon/><br></br>  
  20.                                 <TwitterIcon/> <br></br>  
  21.                                 <LinkedInIcon/><br></br>  
  22.                                 <MailIcon/><br></br>  
  23.                                 <InstagramIcon/><br></br>  
  24.                                 <YouTubeIcon/><br></br>  
  25.   
  26.                         </div>  
  27.                 )  
  28.         }  
  29. }  
  30.   
  31. export default Maticon1  
Now add reference of this component in app.js file and run by using 'npm start' command,
 
How To Use Material UI Icons In ReactJS Application
We also add css to the icons to change styles.
  1. import React, { Component } from 'react'  
  2. import FacebookIcon from '@material-ui/icons/Facebook';  
  3. import AppBar from '@material-ui/core/AppBar';  
  4. import Toolbar from '@material-ui/core/Toolbar';  
  5. import YouTubeIcon from '@material-ui/icons/YouTube';  
  6. export class Maticon1 extends Component {  
  7.         render() {  
  8.                 return (  
  9.                         <div>  
  10.                                 <AppBar className="mrg" position="static">  
  11.                                         <Toolbar>  
  12.                                                 <div style={{ 'paddingLeft'"600px" }}>   Material UI Social media Icons</div>  
  13.                                         </Toolbar>  
  14.                                 </AppBar>  
  15.                                 <FacebookIcon style={{ 'color'"Blue" }}/><br></br>  
  16.                                 <YouTubeIcon style={{ 'color'"red" }}/><br></br>  
  17.                         </div>  
  18.                 )  
  19.         }  
  20. }  
  21.   
  22. export default Maticon1  
Now add reference of these components in app.js file,
  1. import React from 'react';  
  2. import logo from './logo.svg';  
  3. import './App.css';  
  4. import Maticon1 from './Maticon1'  
  5.   
  6. function App() {  
  7.   return (  
  8.     <div className="App">  
  9.       <Maticon1/>  
  10.     </div>  
  11.   );  
  12. }  
  13.   
  14. export default App;  
Now run the project and check result.
 
How To Use Material UI Icons In ReactJS Application

Summary

 
In this article, we learned how to use the Material-UI Icons in a React application. React Material UI provides more then 1000 icons. Material UI is one of the most popular UI frameworks developed by Google. The Material UI library is designed for faster, easier and developer friendly user interface development.