Grid

Arranges items into responsive columns with one shared gap.

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

Preview

import { Card } from '@usefragments/ui';
import { Grid } from '@usefragments/ui';

<Grid columns={3} gap="md">
  <Card>One</Card>
  <Card>Two</Card>

Usage

Use when

  • Cards, tiles, or media that reflow as their container narrows
  • Multi-column form layouts
  • Dashboard widget layouts
  • Feature mosaics: Grid.Item colSpan and rowSpan around a Card

Avoid when

  • One-directional lists (use Stack)
  • Navigation bars (use Header)

Implementation notes

  • columns="auto" with minChildWidth adapts to the grid's own width
  • A count plus minChildWidth caps the tracks and drops them as the pane narrows — no viewport breakpoints
  • gap reads the one layout scale; the shell owns the page gutter and surfaces own their inset, so Grid has no padding
  • Wrap a child in Grid.Item to span columns; colSpan="full" spans the row
  • Keep source order equal to visual order — Grid does not reorder for screen readers

Installation

pnpm add @usefragments/ui

Import styles once from @usefragments/ui/styles. See the installation guide for framework and theme setup.

Anatomy

Import Grid once, then compose its parts with dot notation.

  • Grid.Item

Examples

Capped Columns

Up to three tracks, never thinner than 14rem; tracks drop as the grid narrows.

import { Card } from '@usefragments/ui';
import { Grid } from '@usefragments/ui';

<Grid columns={3} minChildWidth="14rem" gap="md">
  <Card>One</Card>
  <Card>Two</Card>

Auto-fill

As many tracks as fit at the minimum width.

import { Card } from '@usefragments/ui';
import { Grid } from '@usefragments/ui';

<Grid columns="auto" minChildWidth="12rem" gap="md">
  <Card>One</Card>
  <Card>Two</Card>

With Spanning

Grid.Item spans columns; colSpan="full" spans the row.

import { Card } from '@usefragments/ui';
import { Grid } from '@usefragments/ui';

<Grid columns={4} gap="md">
  <Grid.Item colSpan={2}>
    <Card>Spans two</Card>

Form Layout

Two fields side by side, folding to one column below 14rem each.

import { Field } from '@usefragments/ui';
import { Grid } from '@usefragments/ui';
import { Input } from '@usefragments/ui';

<Grid columns={2} minChildWidth="14rem" gap="md">
  <Field>

API reference

Component props
Prop
Type
Default
Description
alignItemsGridAlign | undefinedcenterstartendstretchNot setVertical alignment of items within their cells
childrenReact.ReactNodeNot setGrid items and content
classNamestring | undefinedNot setAdditional class name
columns"auto" | GridColumns | undefined1Column tracks: a count (1, 2, 3, 4, 6, 12) for that many equal minmax(0, 1fr) tracks, or "auto" to fit as many minChildWidth tracks as the width allows. With minChildWidth a count becomes a ceiling that drops tracks as the grid narrows.
gapGridGap | undefinedxssmmdlgnonexlmdSpace between tracks on the layout gap scale: 0, 4, 8, 12, 16, 24
Item.alignSelfGridAlign | undefinedcenterstartendstretchNot setOverride alignment for this item
Item.childrenReact.ReactNodeNot set—
Item.classNamestring | undefinedNot set—
Item.colSpanGridColSpan | undefinedNot setNumber of columns this item spans
Item.rowSpanGridRowSpan | undefinedNot setNumber of rows this item spans
Item.styleReact.CSSProperties | undefinedNot set—
Item.subgridboolean | "both" | "rows" | "columns" | undefinedNot setEnable CSS subgrid so children align to parent grid tracks. - `true` or `"rows"` — children align to parent row tracks - `"columns"` — children align to parent column tracks - `"both"` — children align to both row and column tracks
justifyItemsGridAlign | undefinedcenterstartendstretchNot setHorizontal alignment of items within their cells
minChildWidthstring | undefinedNot setNarrowest a track may get, as a CSS length. Defaults to the grid-cell measure for columns="auto"; with a count it turns the count into a ceiling. Measured against the grid's own width, never the viewport.
styleReact.CSSProperties | undefinedNot 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
  • CardchildGrid commonly contains Card components for dashboard and tile layouts
  • SeparatorsiblingUse Separator between grid sections

Next steps