Grid
Usage
Gutter
Set gutter, gutterXs, gutterSm, gutterMd, gutterLg, gutterXl props to Grid component
to control spacing between columns:
Grow
Set grow prop on Grid component to force all rows to take 100% of container width:
Column offset
Set offset prop on Grid.Col component to create gaps in grid.
offset adds left margin to target column and has the same units as span:
Order
Set the order prop on Grid.Col component to change the order of columns:
Multiple rows
Once children columns span and offset sum exceeds columns prop (defaults to 12),
columns are placed on next row:
Justify and align
Since grid is a flexbox container, you can control justify-content and align-items properties:
Responsive columns
Use breakpoint props (xs, sm, md, lg, xl) to make columns respond to viewport changes.
You can configure breakpoint values with MantineProvider.
In this example up to md there will be 1 column, from md to lg there will be 2 columns and from lg and up, there will be 4 columns:
Auto sized columns
All columns in a row with span or a breakpoint of auto will have equal size, growing as much as they can to fill the row.
In this example, the second column takes up 50% of the row while the other two columns automatically resize to fill the remaining space:
Fit column content
If you set span or a breakpoint to content, the column's size will automatically adjust to match the width of its content:
Change columns count
By default, grid uses 12 columns layout, you can change it by setting columns prop on Grid component.
Note that in this case, columns span and offset will be calculated relative to this value.
In this example, first column takes 50% with 12 span (12/24), second and third take 25% (6/24):
Negative margins
Grid component includes negative margins to align it with the rest of the content.
Due to this you may have horizontal scrollbar if you use Grid in an element without padding.
To fix this issue either wrap Grid with Container or remove margin with
m prop:
Grid component props
| Name | Type | Description |
|---|---|---|
| align | AlignContent | Set grid align-content property |
| children * | ReactNode | <Col /> components only |
| columns | number | Amount of columns in each row |
| grow | boolean | Should columns in the last row take 100% of grid width |
| gutter | number | "xs" | "sm" | "md" | "lg" | "xl" | Spacing between columns, key of theme.spacing or number for value in px |
| gutterLg | number | "xs" | "sm" | "md" | "lg" | "xl" | Gutter when screen size is larger than theme.breakpoints.lg |
| gutterMd | number | "xs" | "sm" | "md" | "lg" | "xl" | Gutter when screen size is larger than theme.breakpoints.md |
| gutterSm | number | "xs" | "sm" | "md" | "lg" | "xl" | Gutter when screen size is larger than theme.breakpoints.sm |
| gutterXl | number | "xs" | "sm" | "md" | "lg" | "xl" | Gutter when screen size is larger than theme.breakpoints.xl |
| gutterXs | number | "xs" | "sm" | "md" | "lg" | "xl" | Gutter when screen size is larger than theme.breakpoints.xs |
| justify | JustifyContent | Set grid justify-content property |
Grid.Col component props
| Name | Type | Description |
|---|---|---|
| lg | ColSpan | Col span at (min-width: theme.breakpoints.lg) |
| md | ColSpan | Col span at (min-width: theme.breakpoints.md) |
| offset | number | Column left offset |
| offsetLg | number | Column left offset at (min-width: theme.breakpoints.lg) |
| offsetMd | number | Column left offset at (min-width: theme.breakpoints.md) |
| offsetSm | number | Column left offset at (min-width: theme.breakpoints.sm) |
| offsetXl | number | Column left offset at (min-width: theme.breakpoints.xl) |
| offsetXs | number | Column left offset at (min-width: theme.breakpoints.xs) |
| order | Order | Default col order |
| orderLg | Order | Col order at (min-width: theme.breakpoints.lg) |
| orderMd | Order | Col order at (min-width: theme.breakpoints.md) |
| orderSm | Order | Col order at (min-width: theme.breakpoints.sm) |
| orderXl | Order | Col order at (min-width: theme.breakpoints.xl) |
| orderXs | Order | Col order at (min-width: theme.breakpoints.xs) |
| sm | ColSpan | Col span at (min-width: theme.breakpoints.sm) |
| span | ColSpan | Default col span |
| xl | ColSpan | Col span at (min-width: theme.breakpoints.xl) |
| xs | ColSpan | Col span at (min-width: theme.breakpoints.xs) |