Grid
A responsive CSS grid: set a base column count and add breakpoints. GridItem spans columns and rows, and never leaks props to the DOM.
Install
Install the component
Add the source straight into your project with the shadcn CLI — no package dependency to track.
npx shadcn@latest add https://vert-ui.dev/r/grid.jsonPreview
Live preview
1
2
3
4
5
6
Usage
Examples
Card grid that reflows
Plan
One of three columns.
Build
One of three columns.
Ship
One of three columns.
<Grid columns={1} smColumns={2} lgColumns={3} gap={4}>
<Card>…</Card>
<Card>…</Card>
<Card>…</Card>
</Grid>Sidebar and content
Sidebar
Content
<Grid lgColumns={12} gap={6}>
<GridItem lgColSpan={3}>Sidebar</GridItem>
<GridItem lgColSpan={9}>Content</GridItem>
</Grid>A banner spanning every column
newFull-width banner
1
2
3
4
<Grid columns={2} mdColumns={4} gap={3}>
<GridItem colSpan="full">Full-width banner</GridItem>
<Cell>1</Cell>
<Cell>2</Cell>
</Grid>Auto-fit without breakpoints
auto
fit
tracks
<Grid autoFit minItemWidth="14rem" gap={4}>
<Cell>…</Cell>
<Cell>…</Cell>
<Cell>…</Cell>
</Grid>Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | 1 | 2 | … | 12 | none | 1 | Base column count (grid-cols-*). |
| smColumns / mdColumns / lgColumns / xlColumns | 1 | 2 | … | 12 | none | — | Column count from each breakpoint up — the responsive core of the grid. |
| gap | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 4 | Row and column gap on the token scale. |
| smGap / mdGap / lgGap | same scale | — | Gap overrides from each breakpoint up. |
| align | "start" | "center" | "end" | "stretch" | "baseline" | — | Aligns items within their grid cells. |
| autoFit | boolean | false | Responsive tracks that fit as many columns as possible — no breakpoints needed. Overrides the column props. |
| minItemWidth | string | "14rem" | Minimum track width for autoFit. Any CSS length; keep it below your smallest container (~14rem fits a padded 320px viewport). |
| templateColumns | string | — | Fully custom grid-template-columns, e.g. "minmax(0,1fr) 200px". Overrides columns and autoFit. |
| templateRows | string | — | Custom grid-template-rows. |
| GridItem · colSpan | 1 | 2 | … | 12 | full | auto | — | How many columns the item spans (col-span-*). |
| GridItem · smColSpan / mdColSpan / lgColSpan / xlColSpan | 1 | 2 | … | 12 | full | auto | — | Responsive span for the item. |
| GridItem · rowSpan | 1 | 2 | … | 6 | full | — | How many rows the item spans (row-span-*). |
Accessibility
Accessibility notes
- Grid and GridItem are structural divs: they add no landmark or role, so author the heading and list semantics of the content inside them.
- DOM order is the source of truth — columns wrap responsively without reordering, so focus and screen-reader order stay predictable.
- GridItem sets min-width: 0 so long words or code inside a cell shrink instead of forcing the whole grid wider than the viewport.