Stack
Stack is a one-dimensional container component for arranging elements vertically or horizontally with consistent spacing.Basic usage
Direction
By default, Stack arranges items vertically. Use thedirection prop to change this:
Spacing
Control spacing between children:Dividers
Add dividers between children:Responsive direction
Change direction based on breakpoint:Flexbox properties
Stack supports all flexbox properties via the sx prop or SystemProps:Using flexGap
By default, Stack uses margin for spacing. Enable CSS flexbox gap withuseFlexGap:
Props
StackProps
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The content of the component |
direction | ResponsiveStyleValue<'row' | 'row-reverse' | 'column' | 'column-reverse'> | 'column' | Defines the flex-direction |
spacing | ResponsiveStyleValue<number | string> | 0 | Defines space between children |
divider | React.ReactNode | - | Element inserted between each child |
useFlexGap | boolean | false | If true, uses CSS flexbox gap instead of margin |
component | React.ElementType | 'div' | The component used for the root node |
sx | SxProps<Theme> | - | System prop for defining custom styles |
Common patterns
Form actions
Navigation breadcrumbs
Card layout
Sidebar navigation
Alert with actions
Image gallery
Limitations
When using the default margin-based spacing (withoutuseFlexGap):
- Negative margin is applied to the Stack container to offset child margins
- This can cause issues if you need the container to respect box model boundaries
- Absolute positioned children may not respect spacing
useFlexGap to true, or configure it globally in your theme: