How to align center mui list in react js?
February 05, 2024Hi Friends 👋,
Welcome To aGuideHub!
To align center mui list in react js, you can use sx={{ display: "flex", justifyContent: "center" }}
in ListItem. It will align center mui list in React JS.
Today, I am going to show you, How to align center mui list in react js
Installation
Install the following packages mui list in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
Table of contents
- Install MUI and create a new React app.
- Import Material-UI list.
- Use the list Component.
Step 1: Install MUI and create a new React app.
First you have to install the React project. You should use create-react-app
command to create a new React project.
npx create-react-app my-app
cd my-app
npm start
Step 2: Import Material-UI list.
After installing MUI
, you have to import your React component. To do this, add the following line to the top of your component file.
import React from 'react';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
Step 3: Use the list Component.
Lists are a continuous group of text or images. They are composed of items containing primary and supplemental actions, which are represented by icons and text.
<List>
<ListItem sx={{ display: "flex", justifyContent: "center" }}>Item 1</ListItem>
<ListItem sx={{display:"flex", justifyContent:"center"}}>Item 2</ListItem>
<ListItem sx={{display:"flex", justifyContent:"center"}}>Item 3</ListItem>
</List>
MUI material align center mui list example.
The below code is an example, you need to import list
Component. Then, you can use sx={{ display: "flex", justifyContent: "center" }}
in ListItem. Then it will align center mui list in react js.
App.js
import React from 'react';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
const CenterAlignedList = () => {
return (
<List>
<ListItem sx={{ display: "flex", justifyContent: "center" }}>Item 1</ListItem>
<ListItem sx={{display:"flex", justifyContent:"center"}}>Item 2</ListItem>
<ListItem sx={{display:"flex", justifyContent:"center"}}>Item 3</ListItem>
</List>
);
};
export default CenterAlignedList;
In the above code example, I have used the @mui/material
component and align center mui list in react js.
All the best 👍