# Grid
A layout component that uses CSS Grid for two-dimensional layouts with configurable columns, rows, gap, flow, justification, and alignment.
```jsx featured
Item 1
Item 2
Item 3
```
```css preview
.grid {
display: grid;
/* Gap */
&[data-gap="0"] {
gap: 0;
}
&[data-gap="1"] {
gap: calc(4px * var(--lcs-spacing, 1));
}
&[data-gap="2"] {
gap: calc(8px * var(--lcs-spacing, 1));
}
&[data-gap="3"] {
gap: calc(12px * var(--lcs-spacing, 1));
}
&[data-gap="4"] {
gap: calc(16px * var(--lcs-spacing, 1));
}
&[data-gap="5"] {
gap: calc(20px * var(--lcs-spacing, 1));
}
&[data-gap="6"] {
gap: calc(24px * var(--lcs-spacing, 1));
}
&[data-gap="7"] {
gap: calc(28px * var(--lcs-spacing, 1));
}
&[data-gap="8"] {
gap: calc(32px * var(--lcs-spacing, 1));
}
/* Columns */
&[data-columns="1"] {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
&[data-columns="2"] {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
&[data-columns="3"] {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
&[data-columns="4"] {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
&[data-columns="5"] {
grid-template-columns: repeat(5, minmax(0, 1fr));
}
&[data-columns="6"] {
grid-template-columns: repeat(6, minmax(0, 1fr));
}
&[data-columns="7"] {
grid-template-columns: repeat(7, minmax(0, 1fr));
}
&[data-columns="8"] {
grid-template-columns: repeat(8, minmax(0, 1fr));
}
&[data-columns="9"] {
grid-template-columns: repeat(9, minmax(0, 1fr));
}
&[data-columns="10"] {
grid-template-columns: repeat(10, minmax(0, 1fr));
}
&[data-columns="11"] {
grid-template-columns: repeat(11, minmax(0, 1fr));
}
&[data-columns="12"] {
grid-template-columns: repeat(12, minmax(0, 1fr));
}
/* Rows */
&[data-rows="1"] {
grid-template-rows: repeat(1, minmax(0, 1fr));
}
&[data-rows="2"] {
grid-template-rows: repeat(2, minmax(0, 1fr));
}
&[data-rows="3"] {
grid-template-rows: repeat(3, minmax(0, 1fr));
}
&[data-rows="4"] {
grid-template-rows: repeat(4, minmax(0, 1fr));
}
&[data-rows="5"] {
grid-template-rows: repeat(5, minmax(0, 1fr));
}
&[data-rows="6"] {
grid-template-rows: repeat(6, minmax(0, 1fr));
}
/* Flow */
&[data-flow="row"] {
grid-auto-flow: row;
}
&[data-flow="column"] {
grid-auto-flow: column;
}
&[data-flow="dense"] {
grid-auto-flow: dense;
}
&[data-flow="row-dense"] {
grid-auto-flow: row dense;
}
&[data-flow="column-dense"] {
grid-auto-flow: column dense;
}
/* Justify Content */
&[data-justify="start"] {
justify-content: start;
}
&[data-justify="end"] {
justify-content: end;
}
&[data-justify="center"] {
justify-content: center;
}
&[data-justify="between"] {
justify-content: space-between;
}
&[data-justify="around"] {
justify-content: space-around;
}
&[data-justify="evenly"] {
justify-content: space-evenly;
}
/* Align Items */
&[data-align="start"] {
align-items: start;
}
&[data-align="end"] {
align-items: end;
}
&[data-align="center"] {
align-items: center;
}
&[data-align="stretch"] {
align-items: stretch;
}
&[data-align="baseline"] {
align-items: baseline;
}
}
```
[View Source](https://github.com/LocusInc/locus-ui/tree/main/packages/locus-ui/src/components/grid)
## Anatomy
```jsx code no-header
```
## Examples
### Gaps
The `gap` prop controls the spacing between grid items using predefined scale values `0` through `8`.
```jsx
{["0", "1", "2", "3", "4", "5", "6", "7", "8"].map((gap) => (
{gap}
Item 1
Item 2
))}
```
### Columns
The `columns` prop sets the number of grid columns: `1` through `12`.
```jsx
{["1", "2", "3", "4", "5", "6"].map((col) => (
{col}
{Array.from({ length: Number(col) }).map((_, i) => (
Item {i + 1}
))}
))}
```
### Rows
The `rows` prop sets the number of grid rows: `1` through `6`.
```jsx
{["1", "2", "3", "4", "5", "6"].map((row) => (
{row}
{Array.from({ length: Number(row) }).map((_, i) => (
Item {i + 1}
))}
))}
```
### Flow
The `flow` prop controls the auto-placement direction: `row`, `column`, `dense`, `row-dense`, or `column-dense`.
```jsx
{["row", "column", "dense", "row-dense", "column-dense"].map((flow) => (
{flow}
Item 1
Item 2
Item 3
Item 4
Item 5
))}
```
### Justify
The `justify` prop controls the inline-axis alignment: `start`, `end`, `center`, `between`, `around`, or `evenly`.
```jsx
{["start", "end", "center", "between", "around", "evenly"].map(
(justify) => (
{justify}
Item 1
Item 2
),
)}
```
### Align
The `align` prop controls the block-axis alignment: `start`, `end`, `center`, `stretch`, or `baseline`.
```jsx
{["start", "end", "center", "stretch", "baseline"].map((align) => (
{align}
Item 1
Item 2
))}
```