logo

SINGULARITY

DOCS

PurchaseReturn to the Dashboard
Reference

Grid

The responsive layout grid adjusts to varying screen sizes and orientations, promoting uniformity across different layouts.

The Grid component is ideal for layouts with a fixed number of columns. It allows multiple breakpoints to define the column span for each child element.

How it works

The grid system is built with the Grid component:
  • It employs CSS Flexbox (instead of CSS Grid) for enhanced adaptability.
  • The grid is inherently a flex item. Apply the container prop to create a flex container.
  • Item widths are set in percentages, ensuring they remain fluid and scale relative to their parent container.
  • Five default grid breakpoints are provided: xs, sm, md, lg, and xl. For custom breakpoints, see custom breakpoints grid.
  • You can assign integer values to each breakpoint to specify how many of the 12 available columns a component occupies when the viewport width meets the breakpoint constraints.
  • It uses the gap CSS property to manage spacing between items.
  • It does not support row spanning, meaning child elements cannot span multiple rows. For this functionality, consider using CSS Grid.
  • It does not feature automatic child placement. It places children sequentially, moving to the next line if space is insufficient. For auto-placement, use CSS Grid instead.
:::warning The Grid component is designed for layout purposes, not as a data grid. For data grids, explore the MUI X DataGrid component. :::

Fluid grids

Fluid grids employ columns that dynamically scale and resize content. Breakpoints can be used to determine when the layout requires significant adjustments.

Basic grid

To create a grid layout, you need a container. Use the container prop to establish a grid container that encloses the grid items (the Grid is always an item).
Column widths are defined as integer values between 1 and 12. For instance, an item with size={6} spans half the width of the grid container.
size=8
size=4
size=4
size=8

Multiple breakpoints

Items can have multiple defined widths, prompting layout changes at specific breakpoints. Width values apply to all larger breakpoints, with values for larger breakpoints overriding those for smaller ones.
For example, a component with size={{ xs: 12, sm: 6 }} spans the full viewport width when the viewport is less than 600 pixels wide. Beyond this size, it occupies half the width—six columns instead of 12.
xs=6 md=8
xs=6 md=4
xs=6 md=4
xs=6 md=8

Spacing

Control the spacing between child elements using the spacing prop. This value can be any positive number (including decimals) or a string, and is converted into a CSS property via the theme.spacing() helper.
The following example demonstrates the application of the spacing prop:
spacing
<Grid container spacing={2}>

Row and column spacing

The rowSpacing and columnSpacing props allow independent specification of row and column gaps, akin to the row-gap and column-gap properties in CSS Grid.
1
2
3
4

Responsive values

Prop values can be adjusted dynamically based on the active breakpoint. For example, this enables the implementation of Material Design's recommended responsive layout grid, as shown in the following example:
1
2
3
4
5
6