<Grid
display="grid"
columns={3}
gap={3}
>
<Placeholder>One</Placeholder>
<Placeholder>Two</Placeholder>
<Placeholder>Three</Placeholder>
<Placeholder>Four</Placeholder>
<Placeholder>Five</Placeholder>
<Placeholder>Six</Placeholder>
</Grid>Features
- Supports grid, inline grid, and flex column display.
- Creates responsive columns and gaps.
- Spans items or places them in named areas.
- Packs extra rows automatically.
- Aligns content within cells.
- Renders different HTML elements with
as.
Display
display is required: grid for a block-level grid, inline-grid for an inline one. On mobile, flex-column stacks children in source order and ignores item placement, so you don't need to reset each Grid.Item. Use a breakpoint object to switch back to grid on larger screens.
import { Grid, Placeholder } from "@vortexlabs/vortex";
<Grid display={{ xs: "flex-column", md: "grid" }} columns={3} gap={3}>
<Placeholder>One</Placeholder>
<Placeholder>Two</Placeholder>
<Placeholder>Three</Placeholder>
</Grid>Columns
Pass a number to columns for equal-width columns. Children fill the cells in order.
<Grid display="grid" columns={3} gap={3}>
<Placeholder>One</Placeholder>
<Placeholder>Two</Placeholder>
<Placeholder>Three</Placeholder>
</Grid>Responsive Columns
Pass a breakpoint object to change the column count by screen size.
<Grid display="grid" columns={{ xs: 1, sm: 2, lg: 3 }} gap={{ xs: 3, md: 5 }}>
<Placeholder>Overview</Placeholder>
<Placeholder>Activity</Placeholder>
<Placeholder>Members</Placeholder>
</Grid>Custom Tracks
Pass a CSS string to columns for unequal widths.
<Grid display="grid" columns={{ xs: "1fr", sm: "10rem 1fr" }} gap={4}>
<Placeholder height={24}>Sidebar</Placeholder>
<Placeholder height={24}>Main content</Placeholder>
</Grid>Row and Column Gaps
Use rowGap and columnGap when each axis needs different spacing. They override gap and use theme spacing units.
<Grid display="grid" columns={2} columnGap={6} rowGap={2}>
<Placeholder>One</Placeholder>
<Placeholder>Two</Placeholder>
<Placeholder>Three</Placeholder>
<Placeholder>Four</Placeholder>
</Grid>Spanning Items
Wrap content in Grid.Item and set columns or rows with CSS grid-line syntax to span several cells.
<Grid display="grid" columns={3} gap={3}>
<Grid.Item columns="1 / -1">
<Placeholder>Full-width header</Placeholder>
</Grid.Item>
<Grid.Item columns="span 2">
<Placeholder height={24}>Main content</Placeholder>
</Grid.Item>
<Grid.Item rows="span 2">
<Placeholder height="100%">Aside</Placeholder>
</Grid.Item>
<Grid.Item columns="span 2">
<Placeholder>Footer</Placeholder>
</Grid.Item>
</Grid>Auto Placement
autoRows sets the height of rows created as items fill the grid. Set autoFlow="row-dense" to fill gaps left by spanning items with later ones.
<Grid display="grid" columns={3} autoRows={20} autoFlow="row-dense" gap={3}>
<Grid.Item columns="span 2">
<Placeholder height="100%">One</Placeholder>
</Grid.Item>
<Grid.Item columns="span 2">
<Placeholder height="100%">Two</Placeholder>
</Grid.Item>
<Placeholder height="100%">Three</Placeholder>
<Placeholder height="100%">Four</Placeholder>
</Grid>Named Areas
Name areas with gridTemplateAreas on the grid, then place each item with a matching gridArea.
<Grid
display="grid"
columns={{ xs: 1, sm: "1fr 2fr" }}
gridTemplateAreas={{
xs: '"header" "sidebar" "main"',
sm: '"header header" "sidebar main"',
}}
gap={3}
>
<Grid.Item gridArea="header">
<Placeholder>Header</Placeholder>
</Grid.Item>
<Grid.Item gridArea="sidebar">
<Placeholder height={24}>Sidebar</Placeholder>
</Grid.Item>
<Grid.Item gridArea="main">
<Placeholder height={24}>Main</Placeholder>
</Grid.Item>
</Grid>Alignment
alignItems and justifyItems position content inside its cells. A Grid.Item can override them with alignSelf and justifySelf.
<Grid
display="grid"
columns={3}
height="10rem"
alignItems="center"
justifyItems="center"
padding={3}
backgroundColor="surface-subtlest"
>
<Grid.Item alignSelf="start">
<Placeholder width={16}>Start</Placeholder>
</Grid.Item>
<Placeholder width={16}>Center</Placeholder>
<Grid.Item alignSelf="end">
<Placeholder width={16}>End</Placeholder>
</Grid.Item>
</Grid>Semantic Elements
Use as to render a semantic element and attributes for its native attributes. For a list, render each child as a Grid.Item with as="li".
- Website
- Mobile app
- Design system
<Grid
as="ul"
display="grid"
columns={{ xs: 1, sm: 3 }}
gap={4}
attributes={{ "aria-label": "Projects" }}
>
<Grid.Item as="li">
<Text>Website</Text>
</Grid.Item>
<Grid.Item as="li">
<Text>Mobile app</Text>
</Grid.Item>
<Grid.Item as="li">
<Text>Design system</Text>
</Grid.Item>
</Grid>Accessibility
as when the content is a list or region.autoFlow change visual position only; reading and keyboard order follow the source.