Grid
A primitive useful for grid layouts. Grid is Box with display: grid and it
comes with helpful style shorthand. It renders a div element.
Import#
import { Grid, GridItem } from "@chakra-ui/react"
- Grid: The main wrapper with
display: grid. - GridItem: Used as a child of
Gridto control the span, and start positions within the grid.
Template columns#
Here's an example of using grid template columns with the grid component, and
applying a gap or space between the grid items.
Spanning columns#
In some layouts, you may need certain grid items to span specific amount of
columns or rows instead of an even distribution. To achieve this, you need to
pass the colSpan prop to the GridItem component to span across columns and
also pass the rowSpan component to span across rows. You also need to specify
the templateColumns and templateRows.
Starting and ending lines#
Pass the colStart and colEnd prop to GridItem component to make an element
start or end at the nth grid position.
Props#
Grid Props#
Grid composes Box so you can pass all the Box prop, and these shorthand prop
to save you some time:
Props#
| Name | Type | Description | Default |
|---|---|---|---|
| area | SystemProps["gridArea"] | Short hand prop for `gridArea` | - |
| autoColumns | SystemProps["gridAutoColumns"] | Short hand prop for `gridAutoColumns` | - |
| autoFlow | SystemProps["gridAutoFlow"] | Short hand prop for `gridAutoFlow` | - |
| autoRows | SystemProps["gridAutoRows"] | Short hand prop for `gridAutoRows` | - |
| column | SystemProps["gridColumn"] | Short hand prop for `gridColumn` | - |
| columnGap | SystemProps["gridColumnGap"] | Short hand prop for `gridColumnGap` | - |
| gap | SystemProps["gridGap"] | Short hand prop for `gridGap` | - |
| row | SystemProps["gridRow"] | Short hand prop for `gridRow` | - |
| rowGap | SystemProps["gridRowGap"] | Short hand prop for `gridRowGap` | - |
| templateAreas | SystemProps["gridTemplateAreas"] | Short hand prop for `gridTemplateAreas` | - |
| templateColumns | SystemProps["gridTemplateColumns"] | Short hand prop for `gridTemplateColumns` | - |
| templateRows | SystemProps["gridTemplateRows"] | Short hand prop for `gridTemplateRows` | - |
GridItem Props#
| Name | Type | Description | Default |
|---|---|---|---|
| colEnd | number | "auto" | ResponsiveArray<number | "auto"> | Partial<Record<string, number | "auto">> | - | |
| colSpan | ResponsiveValue<number | "auto"> | The number of columns the grid item should `span`. | - |
| colStart | ResponsiveValue<number | "auto"> | The column number the grid item should start. | - |
| rowEnd | number | "auto" | ResponsiveArray<number | "auto"> | Partial<Record<string, number | "auto">> | - | |
| rowSpan | number | "auto" | ResponsiveArray<number | "auto"> | Partial<Record<string, number | "auto">> | - | |
| rowStart | number | "auto" | ResponsiveArray<number | "auto"> | Partial<Record<string, number | "auto">> | - |