Skip to main content

Grid

Grid is a layout for managing grid layouts

Import

import { Grid, GridItem } from "@chakra-ui/react";
  • Grid: The main wrapper with display: grid.
  • GridItem: Used as a child of Grid to 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.

Template areas

The templateAreas prop specifies areas within the grid layout. Use template literals to name the area. Now you can reference the area by passing area prop in the <GridItem /> component.

Props

Grid Props

Grid composes Box so you can pass all the Box prop, and these shorthand prop to save you some time:

autoColumns

Description

Shorthand prop for gridAutoColumns

Type
SystemProps["gridAutoColumns"]

autoFlow

Description

Shorthand prop for gridAutoFlow

Type
SystemProps["gridAutoFlow"]

autoRows

Description

Shorthand prop for gridAutoRows

Type
SystemProps["gridAutoRows"]

column

Description

Shorthand prop for gridColumn

Type
SystemProps["gridColumn"]

row

Description

Shorthand prop for gridRow

Type
SystemProps["gridRow"]

templateAreas

Description

Shorthand prop for gridTemplateAreas

Type
SystemProps["gridTemplateAreas"]

templateColumns

Description

Shorthand prop for gridTemplateColumns

Type
SystemProps["gridTemplateColumns"]

templateRows

Description

Shorthand prop for gridTemplateRows

Type
SystemProps["gridTemplateRows"]

GridItem Props

area

Description

Shorthand prop for gridArea

Type
SystemProps["gridArea"]

colEnd

Type
ResponsiveValue<number | "auto">

colSpan

Description

The number of columns the grid item should span.

Type
ResponsiveValue<number | "auto">

colStart

Description

The column number the grid item should start.

Type
ResponsiveValue<number | "auto">

rowEnd

Type
ResponsiveValue<number | "auto">

rowSpan

Type
ResponsiveValue<number | "auto">

rowStart

Type
ResponsiveValue<number | "auto">