SimpleGrid

If you're like me, you probably tend to check the MDN docs for anything CSS grid.

SimpleGrid provides a friendly interface to create responsive grid layouts with ease. It renders a div element with display: grid.

Import#

import { SimpleGrid } from "@chakra-ui/react"

Usage#

Specifying the number of columns for the grid layout.

Editable Example

You can also make it responsive by passing array or object values into the columns prop.

Editable Example

Auto-responsive grid#

To make the grid responsive and adjust automatically without passing columns, simply pass the minChildWidth prop to specify the min-width a child should have before adjusting the layout.

This uses css grid auto-fit and minmax() internally.

Editable Example

Changing the spacing for columns and rows#

Simply pass the spacing prop to change the row and column spacing between the grid items. SimpleGrid also allows you pass spacingX and spacingY to define the space between columns and rows respectively.

Editable Example

Props#

SimpleGrid composes Box so you can pass all the Box props and css grid props with addition of these:

NameTypeDescriptionDefault
areaSystemProps["gridArea"]Short hand prop for `gridArea`-
autoColumnsSystemProps["gridAutoColumns"]Short hand prop for `gridAutoColumns`-
autoFlowSystemProps["gridAutoFlow"]Short hand prop for `gridAutoFlow`-
autoRowsSystemProps["gridAutoRows"]Short hand prop for `gridAutoRows`-
columnSystemProps["gridColumn"]Short hand prop for `gridColumn`-
columnGapSystemProps["gridColumnGap"]Short hand prop for `gridColumnGap`-
columnsnumber | ResponsiveArray<number> | Partial<Record<string, number>>The number of columns-
gapSystemProps["gridGap"]Short hand prop for `gridGap`-
minChildWidthnumber | "px" | (string & {}) | "sm" | "md" | "lg" | "xl" | "2xl" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | ... 47 more ...The width at which child elements will break into columns. Pass a number for pixel values or a string for any other valid CSS length.-
rowSystemProps["gridRow"]Short hand prop for `gridRow`-
rowGapSystemProps["gridRowGap"]Short hand prop for `gridRowGap`-
spacingnumber | "px" | (string & {}) | "sm" | "md" | "lg" | "xl" | "2xl" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | ... 38 more ...The gap between the grid items-
spacingXnumber | "px" | (string & {}) | "sm" | "md" | "lg" | "xl" | "2xl" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | ... 38 more ...The column gap between the grid items-
spacingYnumber | "px" | (string & {}) | "sm" | "md" | "lg" | "xl" | "2xl" | "-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | ... 38 more ...The row gap between the grid items-
templateAreasSystemProps["gridTemplateAreas"]Short hand prop for `gridTemplateAreas`-
templateColumnsSystemProps["gridTemplateColumns"]Short hand prop for `gridTemplateColumns`-
templateRowsSystemProps["gridTemplateRows"]Short hand prop for `gridTemplateRows`-