How to Use Material UI (MUI) Icons in React
Tags: react, javascript, programming, webdev
Published: 2021-12-13 05:42:17


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqxhacgfsp3gqxyjkw75.jpg)

Whether it’s about a simple landing page, an e-commerce app platform or your company’s internal dashboard, using a library of pre-made icons and components is highly beneficial. There are many other icon libraries out there which can ease your work but one of the largest and the most popular one is the Material UI (or recently named MUI) icon library.

If you are new to Material UI library, it provides you with a robust, customizable,  accessible and advanced components, enabling you to build your own design system and develop React applications faster. That includes a huge list of Material icons.

Material UI icons or MUI currently have over 1900 icons based on [Material Design](https://material.io/design) guidelines set by Google. So let’s see how to use them in a React application. Let’s begin!

##Getting Started with Material Icons in a React App##

Let’s get our hands dirty with some actual coding where our React app uses the Material Icons (MUI) package.

###What we will be making?###
Our demo will be a very basic one. Basically, a component where we display three of the common items found in a typical webpage; 


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xm7pkym4148w5qxsj1cq.PNG)

As you can see, we have three items:

The “More” dropdown item.
The “Menu” hamburger item.
The “Cart” icon.
Here we are using the Material Icons alongside the texts. 


##Step 1: Start a New React Project##


Make sure you have [Node.js installed](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm/) on your system and then run the following commands:


`npx create-react-app mui-demo
cd mui-demo
npm start`

This will bootstrap a new React application and run the default app on [http://localhost:3000/](http://localhost:3000/) in your default browser thanks to the [Create React App](https://create-react-app.dev/) tool.


##Step 2: Install Material UI(MUI) Package##

Before we start adding these icons, we need the core MUI package because all these icons uses the MUI [SvgIcon](https://mui.com/api/svg-icon/#main-content) component to render the SVG path for each icon. For each SVG icon, we export the respective React component from the` @mui/icons-material` package.

Run the following command from your terminal:

`npm install @mui/material @emotion/react @emotion/styled`

Or if you are using Yarn:

`yarn add @mui/material @emotion/react @emotion/styled`

##Step 3: Install Material icons package##

Now we can install the icon package with the following command


`// with npm
npm install @mui/icons-material
`
`// with yarn
yarn add @mui/icons-material`

##Step 4: Start using MUI icons!##

Simply head over to the app.js file and delete all the existing code. We will be writing everything from scratch.

Let’s start with the responsive [Grid](https://mui.com/components/grid/#main-content) layout component which will contain all of our elements inside. This is useful for different screen sizes and orientations which uses [CSS Flexbox](https://www.w3.org/TR/css-flexbox-1/) under-the-hood.

So under the return() method, we should have <Grid> component. This can have its props or custom styles attached to it:

`<Grid container></Grid>`

Now we need six new child <Grid> components to hold our icons with the text lables (one for each of the three). Make sure you pass in the item prop to each of them.

`<Grid item xs={1}></Grid>`

Within each of these, we have a [<Typography>](https://mui.com/api/typography/#main-content) component holding the text label

`<Typography>More</Typography>`

As for the actual MUI icon component we will create a duplicate child <Grid> item but the only thing changed here will be the actual icon component name. By now we should have the following code:


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4xs52uprlzx8ecd1k9b.PNG)

Let’s see how to find icons we need from the MUI website:

1. Head over to the [Material Icons webpage](https://mui.com/components/material-icons/).
2. Here you will see a list of icons:


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebsm8nh1w1ry7vhxzh54.PNG)

As you can see it has 5 types of icons: Filled, Outlined, Rounded, Two tone, and Sharp. For this demo we only want to use the Outlined one. 

3. Now let’s search for the four icons by name let’s say the menu icon:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seytkwarhge4cmxzm05m.PNG)

4. If you click on the selected icon you will be greeted with the following popup:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2rvgaqzfn2ux3k5biei.PNG)

Here you get the icon component’s name along with some variants. 

5. Finally, let’s copy the import statement you see in the modal above so that we can use it on our React application.

Inside the second child <Grid> component we can now safely add the selected icon component as:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pks6ayxfdrte899olvw.png)
 

Other icon components used for the above demo are: ExpandMoreOutlinedIcon and ShoppingCartIcon.

If you implemented the above steps successfully, you should have the following code:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ktebnc631q5vmelqpgf.png)
![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kaeo2ft21ni8llizf55h.png)
  

And that should do it! If you followed the above steps carefully, you can see in your browser that React is rendering the corresponding MUI icons as needed.

One of the benefits of using Material UI icons other than the fact that it’s huge with multiple variants is that it is supported by all major platforms, as well as browsers and if you ever get stuck you can definitely check out their [GitHub repo](https://github.com/mui-org/material-ui). If that’s not enough, they have an entire page dedicated to [support](https://mui.com/getting-started/support/).


So go ahead and try to use some other icons available in your project. Hope this short guide helped.

Or you can also browse some of our pre-built react templates at [WrapPixel](https://www.wrappixel.com/templates/category/react-templates/?ref=232) and [AdminMart](https://adminmart.com/templates/material-ui/?ref=6) that are fully-responsive, interactive, and are loaded with all the important Material UI Icons.

---