Skip to content


Stack is a container component for arranging elements vertically or horizontally.


The Stack component manages the layout of its immediate children along the vertical or horizontal axis, with optional spacing and dividers between each child.


import Stack from '@mui/system/Stack';

The Stack component acts as a generic container, wrapping around the elements to be arranged.

Use the spacing prop to control the space between children. The spacing value can be any number, including decimals, or a string. (The prop is converted into a CSS property using the theme.spacing() helper.)

Item 1
Item 2
Item 3
Press Enter to start editing

Stack vs. Grid

Stack is concerned with one-dimensional layouts, while Grid handles two-dimensional layouts. The default direction is column which stacks children vertically.


By default, Stack arranges items vertically in a column. Use the direction prop to position items horizontally in a row:

Item 1
Item 2
Item 3
Press Enter to start editing


Use the divider prop to insert an element between each child, as shown below:

Item 1

Item 2

Item 3

Responsive values

You can switch the direction or spacing values based on the active breakpoint.

Item 1
Item 2
Item 3
Press Enter to start editing

Flexbox gap

To use flexbox gap for the spacing implementation, set the useFlexGap prop to true.

It removes the known limitations of the default implementation that uses CSS nested selector. However, CSS flexbox gap is not fully supported in some browsers.

We recommend checking the support percentage before using it.

Item 1
Item 2
Long content
Press Enter to start editing

Interactive demo

Below is an interactive demo that lets you explore the visual results of the different settings:

Item 1
Item 2
Item 3

System props

As a CSS utility component, the Stack supports all system properties. You can use them as props directly on the component. For instance, a margin-top:

<Stack mt={2}>


Margin on the children

Customizing the margin on the children is not supported by default.

For instance, the top-margin on the button component below will be ignored.

  <button style={{ marginTop: '30px' }}>...</button>

white-space: nowrap

The initial setting on flex items is min-width: auto. This causes a positioning conflict when children use white-space: nowrap;. You can reproduce the issue with:

<Stack direction="row">
  <span style={{ whiteSpace: 'nowrap' }}>

In order for the item to stay within the container you need to set min-width: 0.

<Stack direction="row" sx={{ minWidth: 0 }}>
  <span style={{ whiteSpace: 'nowrap' }}>


The Stack component is composed of a single root <div> element:

<div class="MuiStack-root">
  <!-- Stack contents -->


See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.