Grid is a CSS Grid based React component, comes with predefined values to ensure design consistency, and ease of use.
The Grid consists of two components:
- Grid: Used as a container for grid items
- Grid.Item: Elements within the Grid
Import
import { Grid } from '@contentful/f36-components';// orimport { Grid } from '@contentful/f36-core';
Grid vs. Flexbox
The main difference between CSS Grid Layout and CSS Flexbox Layout is that flexbox was designed for layouts in one dimension - either a row or a column. Grid was designed for two-dimensional layout rows, and columns.

Examples
Basic usage
Repeat notation
repeat() is a css notation that you can use with the gridColumns and girdRows properties to make your rules more concise and easier to understand when creating a large amount of columns or rows
Example: gridColumns="1fr 2fr 1fr 2fr 1fr 2fr" is same as gridColumns="repeat(3, 1fr 2fr)" see below.
FR unit
Fr is a fractional unit and 1fr stands for 1 part of the available space. It differs from percentage unit because it distributes available space.
If you place a larger item into a track then the way the fr until will work is to allow that track to take up more space and distribute what is left over.
Span keyword
Span keyword works on grid items with the gridArea property, use span to avoid specifying the end lines for a column or a row.
i.e. instead of specifying columnStart and columnEnd you can use span to make the grid item take 4 columns
Content alignment
Just like Flex the Grid comes with justifyContent, justifyItems, alignItems, alignContent, ..etc.
Accessibility
According to WCAG C27 technique, the dom order must match the visual order.
The grid can re-order it's content in various ways through the order css property on grid items, this changes the visual order but the dom order stays the same, hence, keyboard navigation and focus order maybe affected.
Set the correct order of the elements with tabindex attribute to avoid accessibility issues.
Props (API reference)
Grid
- NamealignContentDescriptionOne of justify-content css values "end""baseline""inherit""initial""start""center""-moz-initial""revert""unset"string & {}"space-around""space-between""space-evenly""stretch""flex-end""flex-start""normal"
- NameasHTML Tag or React Component (e.g. div, span, etc)
- NamechildrenDescriptionChild nodes to be rendered in the component ReactNode
- NameclassNameDescriptionCSS class to be appended to the root element string
- NamecolumnGapDescriptionOne of Spacing tokens values, default is 0 "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamecolumnsDescriptionDefines how many columns, default is `auto` number"none""auto""inherit""initial""-moz-initial""revert""unset""max-content""min-content"string & {}"subgrid"
- NameflowDescriptionOne of grid-auto-flow css values "inherit""initial""-moz-initial""revert""unset"string & {}"column""dense""row"
- NameisInlineDescriptionSets display:inline-grid falsetrue
- NamejustifyContentDescriptionOne of justify-content css values "end""inherit""initial""start""left""center""right""-moz-initial""revert""unset"string & {}"space-around""space-between""space-evenly""stretch""flex-end""flex-start""normal"
- NamemarginDescriptionsets margin to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginBottomDescriptionsets margin-bottom to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginLeftDescriptionsets margin-left to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginRightDescriptionsets margin-right to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginTopDescriptionsets margin-top to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingDescriptionsets padding to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingBottomDescriptionsets padding-bottom to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingLeftDescriptionsets padding-left to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingRightDescriptionsets padding-right to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingTopDescriptionsets padding-top to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamerowGapDescriptionSpaces between rows, corresponds to of spacing tokens values, default is none "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamerowsDescriptionDefines how many rows, default is `auto` number"none""auto""inherit""initial""-moz-initial""revert""unset""max-content""min-content"string & {}"subgrid"
- NametestIdDescriptionA [data-test-id] attribute used for testing purposes string
Grid.Item
- NameareaDescriptionone of grid-area css values "auto""inherit""initial""-moz-initial""revert""unset"string & {}number & {}
- NameasHTML Tag or React Component (e.g. div, span, etc)
- NamechildrenDescriptionChild nodes to be rendered in the component ReactNode
- NameclassNameDescriptionCSS class to be appended to the root element string
- NamecolumnEndDescriptionone of grid-column-end css values "auto""inherit""initial""-moz-initial""revert""unset"string & {}number & {}
- NamecolumnStartDescriptionone of grid-column-start css values "auto""inherit""initial""-moz-initial""revert""unset"string & {}number & {}
- NamemarginDescriptionsets margin to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginBottomDescriptionsets margin-bottom to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginLeftDescriptionsets margin-left to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginRightDescriptionsets margin-right to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamemarginTopDescriptionsets margin-top to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NameorderDescriptionorder css property number
- NamepaddingDescriptionsets padding to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingBottomDescriptionsets padding-bottom to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingLeftDescriptionsets padding-left to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingRightDescriptionsets padding-right to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamepaddingTopDescriptionsets padding-top to one of the corresponding spacing tokens "none""spacing2Xs""spacingXs""spacingS""spacingM""spacingL""spacingXl""spacing2Xl""spacing3Xl""spacing4Xl"
- NamerowEndDescriptionone of grid-row-end css values "auto""inherit""initial""-moz-initial""revert""unset"string & {}number & {}
- NamerowStartDescriptionone of grid-column-start css values "auto""inherit""initial""-moz-initial""revert""unset"string & {}number & {}
- NametestIdDescriptionA [data-test-id] attribute used for testing purposes string