logo

SINGULARITY

DOCS

PurchaseReturn to the Dashboard
Reference

GridLegacy

The Material Design responsive layout grid adjusts to different screen sizes and orientations, maintaining uniformity across layouts.

The grid ensures visual harmony across layouts while supporting flexibility for a wide range of designs. Material Design's responsive UI relies on a 12-column grid system.
:::warning The GridLegacy component is not intended to function as a data grid; it serves as a layout grid. For a data grid, refer to the DataGrid component. :::
:::warning The GridLegacy component is deprecated. It is recommended to use Grid instead. Consult the Grid upgrade guide for additional information. :::

How it works

The grid system is built using the GridLegacy component:
  • It leverages CSS Flexible Box module for enhanced flexibility.
  • There are two layout types: containers and items.
  • Item widths are defined in percentages, ensuring they remain fluid and scale relative to their parent container.
  • Items include padding to establish spacing between individual elements.
  • Five grid breakpoints are available: xs, sm, md, lg, and xl.
  • Each breakpoint can be assigned integer values to specify how many of the 12 columns a component occupies when the viewport width meets the breakpoint constraints.
If you are new to or unfamiliar with flexbox, we recommend reviewing this CSS-Tricks flexbox guide.

Fluid grids

Fluid grids utilize columns that adjust and resize content dynamically. The layout of a fluid grid can employ breakpoints to determine when significant layout changes are needed.

Basic grid

Column widths are set as integer values from 1 to 12, applicable at any breakpoint, indicating the number of columns a component occupies.
A value assigned to a breakpoint applies to all wider breakpoints unless explicitly overridden. For instance, xs={12} ensures a component spans the entire width of its parent container across all viewport sizes.
xs=8
xs=4
xs=4
xs=8

Grid with multiple breakpoints

Components can have multiple widths defined, triggering layout changes at specified breakpoints. Values set for larger breakpoints take precedence over those for smaller ones.
For example, xs={12} sm={6} makes a component occupy half the viewport width (6 columns) when the viewport is 600 pixels or wider. For smaller viewports, it spans all 12 columns.
xs=6 md=8
xs=6 md=4
xs=6 md=4
xs=6 md=8

Spacing

To manage spacing between child elements, use the spacing prop. This value can be any positive number, including decimals, or any string, and is transformed into a CSS property via the theme.spacing() helper.
spacing
<Grid container spacing={2}>

Row & column spacing

The rowSpacing and columnSpacing props enable independent control over row and column gaps, similar to the row-gap and column-gap properties in CSS Grid.
1
2
3
4

Responsive values

Props can dynamically adjust their values based on the active breakpoint. For example, this allows implementation of Material Design's "recommended" responsive layout grid.
xs=2
xs=2
xs=2
xs=2
xs=2
xs=2
Responsive values are supported for:
  • columns
  • columnSpacing
  • direction
  • rowSpacing
  • spacing
  • all the other props of MUI System
:::warning When using a responsive columns prop, each grid item must have a corresponding value for every breakpoint. For example, this will not work, as the grid item lacks a value for md:
<Grid container columns={{ xs: 4, md: 12 }}>
  <Grid item xs={2} />
</Grid>
:::

Interactive

The following interactive demo allows you to experiment with various settings and observe their visual outcomes:
Cell 1
Cell 2
Cell 3
direction
justifyContent
alignItems
<Grid
  container
  direction="row"
  sx={{
    justifyContent: "center",
    alignItems: "center",
  }}
>

Auto-layout

The Auto-layout feature enables items to evenly distribute available space. This means you can define the width of one item, and the others will automatically adjust around it.
xs
xs=6
xs

Variable width content

By setting a size breakpoint prop to "auto" instead of true or a number, a column can be sized based on the natural width of its content.
variable width content
xs=6
xs

Complex Grid

The following example deviates from Material Design guidelines but demonstrates how the grid can be utilized to create intricate layouts.
Standard license

Full resolution 1920x1080 • JPEG

ID: 1030114

Remove

$19.00

Nested Grid

The container and item props are independent booleans, allowing a Grid component to function as both a flex container and a child simultaneously.
A flex container is an element with a computed display of flex or inline-flex. Its in-flow children, known as flex items, are arranged using the flex layout model.
Item
Item
Item
Item
Item
Item
Item
Item
Item
⚠️ Setting an explicit width on a Grid element that is simultaneously a flex container, flex item, and has spacing can result in unexpected behavior. Avoid combining these properties:
<Grid spacing={1} container item xs={12}>
If necessary, remove one of these props to prevent issues.

Columns

The default number of columns (12) can be modified using the columns prop.
xs=8
xs=8

Limitations

Negative margin

Item spacing is achieved using negative margins, which may cause unexpected results. For example, applying a background color requires setting display: flex; on the parent element.

white-space: nowrap

Flex items have a default min-width: auto, which can conflict with children using white-space: nowrap;. This issue can be replicated with:
<Grid item xs>
  <Typography noWrap>
To keep the item within the container, set min-width: 0. In practice, use the zeroMinWidth prop:
<Grid item xs zeroMinWidth>
  <Typography noWrap>
W

Truncation should be conditionally applicable on this long line of text as this is a much longer line than what the container can support.

W

Truncation should be conditionally applicable on this long line of text as this is a much longer line than what the container can support.

W

Truncation should be conditionally applicable on this long line of text as this is a much longer line than what the container can support.

direction: column | column-reverse

The xs, sm, md, lg, and xl props are not supported in direction="column" or direction="column-reverse" containers.
These props specify the number of grid columns a component occupies at a given breakpoint. They are designed to control width via flex-basis in row containers but may affect height in column containers, potentially causing undesirable effects on the height of GridLegacy items.

CSS Grid Layout

The GridLegacy component internally uses CSS flexbox. However, as demonstrated below, you can seamlessly utilize MUI System and CSS Grid to design your page layouts.
xs=8
xs=4
xs=4
xs=8

System props

System props are deprecated and will be discontinued in the next major release. Use the sx prop as an alternative.
- <Grid item p={2} />
+ <Grid item sx={{ p: 2 }} />