Monday, October 6, 2025
HomeLanguagesReact MUI Stack API

React MUI Stack API

Material-UI is a UI library providing predefined robust and customizable components for React for easier web development. The MUI design is based on top of Material Design by Google. 

In this article, we will discuss the React MUI Stack API. The Stack component is used to manage the immediate children on the horizontal or vertical axis with optional spacing and padding between them. The API provides a lot of functionality and we will learn to implement them.

Import Stack API:

import Stack from '@mui/material/Stack';
// or
import { Stack } from '@mui/material';

Props List: Here is the list of props used with this component. We can access them and modify them according to our needs.

  • children (node): It is the content of the component.
  • component (elementType): It is the component for the root node.
  • sx (Array<func/object/bool> func/object): The system prop allows defining system overrides as well as additional CSS styles. 
  • direction (column-reverse/column/row-reverse/row/array): It defines the flex-direction. The default value is the column.
  • divider (node): Adds a divider between children. 
  • spacing (Array<number/string>/number/object/string): It specifies the spacing between the children. The default value is 0.

CSS Rules: All CSS utilities are supported.

Syntax: Create a Stack element as follows:

<Stack spacing={2}>
      <Item>Tutorial 1</Item>
      <Item>Tutorial 2</Item>
      <Item>Tutorial 3</Item>
</Stack>

Installing and Creating React app, and adding the MUI dependencies:

Step 1: Create a react project using the following command.

npx create-react-app gfg_tutorial

Step 2: Get into the project directory

cd gfg_tutorial

Step 3: Install the MUI dependencies as follows:

npm install @mui/material @emotion/react @emotion/styled @mui/lab @mui/icons-material

Step 4: Run the project as follows:

npm start

Example 1: In the following example, we have a Stack with some items.

App.js

Javascript




import "./App.css";
import * as React from "react";
import Box from "@mui/material/Box";
import Paper from "@mui/material/Paper";
import Stack from "@mui/material/Stack";
import { styled } from "@mui/material/styles";
  
const Item = styled(Paper)(({ theme }) => ({
    backgroundColor: theme.palette
        .mode === "dark" ? "#1A2027" : "#fff",
    ...theme.typography.body2,
    padding: theme.spacing(1),
    textAlign: "center",
    color: theme.palette.text.secondary,
}));
function App() {
    return (
        <div className="App">
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    neveropen
                </h1>
                <strong>React MUI Stack API</strong>
            </div>
            <br />
            <Box sx={{ width: "50%", margin: "auto" }}>
                <Stack spacing={2}>
                    <Item>Data Structures</Item>
                    <Item>Algorithms</Item>
                    <Item>Web Development</Item>
                </Stack>
            </Box>
        </div>
    );
}
  
export default App;


Output:

 

Example 2: In the following example, we have changed from column to row.

App.js

Javascript




import "./App.css";
import * as React from "react";
import Box from "@mui/material/Box";
import Paper from "@mui/material/Paper";
import Stack from "@mui/material/Stack";
import { styled } from "@mui/material/styles";
  
const Item = styled(Paper)(({ theme }) => ({
    backgroundColor: theme.palette
        .mode === "dark" ? "#1A2027" : "#fff",
    ...theme.typography.body2,
    padding: theme.spacing(1),
    textAlign: "center",
    color: theme.palette.text.secondary,
}));
function App() {
    return (
        <div className="App">
            <div
                className="head"
                style={{
                    width: "fit-content",
                    margin: "auto",
                }}
            >
                <h1
                    style={{
                        color: "green",
                    }}
                >
                    neveropen
                </h1>
                <strong>React MUI Stack API</strong>
            </div>
            <br />
            <Box sx={{ 
                width: "fit-content"
                margin: "auto" 
            }}>
                <Stack direction="row" spacing={2}>
                    <Item>Data Structures</Item>
                    <Item>Algorithms</Item>
                    <Item>Web Development</Item>
                </Stack>
            </Box>
        </div>
    );
}
  
export default App;


Output

 

Reference: https://mui.com/material-ui/api/stack/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6781 POSTS0 COMMENTS