Skip to main content

Grid

Arranges items into responsive columns with one shared gap.

import { Grid } from "@/fragments/ui";Source

Preview

import { Box } from '@/components/Box';
import { Grid } from '@/components/Grid';

<Box width="100%">
  <Grid columns={3} gap="md">
    <Box background="secondary" rounded="sm" padding="sm">One</Box>

Installation

npx @usefragments/cli add grid

Writes src/fragments/ui/components/Grid plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

Responsive

Column count changes per breakpoint.

import { Box } from '@/components/Box';
import { Grid } from '@/components/Grid';

<Box width="100%">
  <Grid columns={{ base: 1, md: 2, lg: 3 }} gap="md">
    <Box background="secondary" rounded="sm" padding="sm">Card 1</Box>

Auto-fill

Columns fit themselves to a minimum child width — no breakpoints needed.

import { Box } from '@/components/Box';
import { Grid } from '@/components/Grid';

<Box width="100%">
  <Grid columns="auto" minChildWidth="10rem" gap="md">
    <Box background="secondary" rounded="sm" padding="sm">Card 1</Box>

With Spanning

Grid.Item stretches a child across columns.

import { Box } from '@/components/Box';
import { Grid } from '@/components/Grid';

<Box width="100%">
  <Grid columns={4} gap="md">
    <Grid.Item colSpan={2}>

Form Layout

Paired fields with one full-width row.

import { Box } from '@/components/Box';
import { Field } from '@/components/Field';
import { Grid } from '@/components/Grid';
import { Input } from '@/components/Input';

<Box width="100%">

API

Component props
Prop
Type
Default
Description
childrennodeNot setGrid items and content
columnsunion1Number of columns: a number (1-12), a responsive object { base, sm, md, lg, xl }, or "auto" for auto-fill
minChildWidthstringNot setMinimum width for auto-fill columns (e.g., "16rem", "250px")
gapunionnonexssmmdlgxlmdGap between grid items. Accepts string tokens or numbers (1-8) mapped to the spacing scale
alignItemsenumstartcenterendstretchNot setVertical alignment of items within their cells
justifyItemsenumstartcenterendstretchNot setHorizontal alignment of items within their cells
paddingenumnonesmmdlgnoneInternal padding of the grid container
classNamestringNot setAdditional class name
styleobjectNot setInline styles

Accessibility

  • Grid is purely visual — it does not affect reading order or semantics
  • Ensure logical source order matches visual order for screen readers

Guidance

Use when

  • Cards, tiles, or media that reflow across breakpoints
  • Multi-column form layouts
  • Dashboard widget layouts

Avoid when

  • One-directional lists (use Stack)
  • Editorial mosaics with feature tiles (use BentoGrid)
  • Navigation bars (use Header)
  • CardchildGrid commonly contains Card components for dashboard and tile layouts
  • SeparatorsiblingUse Separator between grid sections

Next steps