<!-- index: /slotted/llms.txt -->
# grid

`data-ui="grid"` · Columns that reflow by available width.

## Minimal example

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

const WAREHOUSES = [
  { name: 'Rotterdam', units: '12,480 units on hand', status: 'Healthy', tone: 'success' },
  { name: 'Chicago', units: '8,215 units on hand', status: 'Low stock', tone: 'warning' },
  { name: 'Singapore', units: '3,902 units on hand', status: 'Delayed', tone: 'danger' },
  { name: 'Lisbon', units: '6,730 units on hand', status: 'Healthy', tone: 'success' },
  { name: 'Osaka', units: '5,118 units on hand', status: 'Audit due', tone: 'info' },
  { name: 'Denver', units: '2,044 units on hand', status: 'Opening soon', tone: 'secondary' },
] as const;

export default function GridBasic() {
  return (
    <Grid>
      {WAREHOUSES.map((warehouse) => (
        <Card key={warehouse.name}>
          <CardBody>
            <Stack gap={3}>
              <Heading level={2} size="md">
                {warehouse.name}
              </Heading>
              <Text size="sm" tone="muted">
                {warehouse.units}
              </Text>
              <Inline>
                <Badge tone={warehouse.tone}>{warehouse.status}</Badge>
              </Inline>
            </Stack>
          </CardBody>
        </Card>
      ))}
    </Grid>
  );
}
```

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `gap` | `0 \| 1 \| … \| 12` | 6 | Grid | Sets the separation between cells as a step on the space scale. |
| `columns` | `1 \| 2 \| … \| 12` | auto | Grid | Sets the most columns a row may hold. When absent, the grid fits as many as it can. |
| `minItemWidth` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl'` | md | Grid | Sets the narrowest a cell may become before a column is dropped. |
| `align` | `'start' \| 'center' \| 'end' \| 'stretch'` | — | Grid | Positions a child along the block axis, inside its own cell. |
| `justify` | `'start' \| 'center' \| 'end' \| 'stretch'` | — | Grid | Positions a child along the inline axis, inside its own cell. |
| `render` | `(props) => ReactNode` | — | Grid | Renders a different root element from the props it receives. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `gap` | `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12` | `6` |
| `align` | `start`, `center`, `end`, `stretch` | — |
| `justify` | `start`, `center`, `end`, `stretch` | — |
| `columns` | `auto`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12` | — |
| `minItemWidth` | `xs`, `sm`, `md`, `lg`, `xl` | `md` |

## Rules

- This is not the APG grid widget. There is no role="grid", no cell and no arrow-key navigation: Grid lays children out, and the children keep whatever semantics they already had.
- There is no prop that reorders or places children. Visual order stays DOM order, which is what WCAG 2.2 SC 1.3.2 asks for (technique C27, failure F1) and what keeps the Tab order matching the page.
- A stated count is a ceiling the grid may lower. Twelve columns become six and then one as the grid narrows, so a page reflows to 320 CSS pixels without scrolling in two dimensions, as WCAG 1.4.10 requires.
- The reflow is measured against the grid’s own inline size, not the viewport, so a grid inside a narrow panel behaves the same as one inside a narrow window. Grid uses no breakpoint and no container query.
- minItemWidth is stated in rem, so the point at which a column is dropped moves with the browser zoom WCAG 1.4.4 requires.

## Tokens

`--slotted-grid-columns`, `--slotted-grid-min-item-width-lg`, `--slotted-grid-min-item-width-md`, `--slotted-grid-min-item-width-sm`, `--slotted-grid-min-item-width-xl`, `--slotted-grid-min-item-width-xs`, `--slotted-space-1`, `--slotted-space-10`, `--slotted-space-11`, `--slotted-space-12`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-space-8`, `--slotted-space-9`

## Examples

### As many cards as fit, never narrower than a card should be

Excerpt — not a complete module

```tsx
<Grid gap={6} minItemWidth="md">
  {workspaces.map((workspace) => (
    <Card key={workspace.id} {...workspace} />
  ))}
</Grid>;
```

### Three columns at most, fewer when the container narrows

Excerpt — not a complete module

```tsx
<Grid columns={3} gap={4} minItemWidth="sm">
  <Metric label="Revenue" />
  <Metric label="Refunds" />
  <Metric label="Disputes" />
</Grid>;
```

### A child that crosses every column states it on itself

Excerpt — not a complete module

```tsx
<Grid columns={2} gap={6}>
  <Panel style={{ gridColumn: '1 / -1' }}>Summary</Panel>
  <Panel>Left</Panel>
  <Panel>Right</Panel>
</Grid>;
```

### align.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const ALIGNS = ['start', 'center', 'end', 'stretch'] as const;

const SHIPMENTS = [
  'Ships today.',
  'Waits for the carrier pickup window on Thursday afternoon.',
  'Held until payment clears and the customs check for the destination country finishes.',
] as const;

export default function GridAlign() {
  return (
    <Stack gap={6}>
      {ALIGNS.map((align) => (
        <Stack key={align} gap={3}>
          <Text size="sm" tone="muted">{`align: ${align}`}</Text>

          <Grid align={align} columns={3} gap={4} minItemWidth="xs">
            {SHIPMENTS.map((shipment) => (
              <Card key={shipment}>
                <CardBody>
                  <Text>{shipment}</Text>
                </CardBody>
              </Card>
            ))}
          </Grid>
        </Stack>
      ))}
    </Stack>
  );
}
```

### columns.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

const COUNTS = [2, 3, 4] as const;

const METRICS = [
  { label: 'Revenue', value: '$48,200' },
  { label: 'Refunds', value: '$1,940' },
  { label: 'Disputes', value: '7' },
  { label: 'Payouts', value: '$44,310' },
] as const;

export default function GridColumns() {
  return (
    <Stack gap={6}>
      {COUNTS.map((count) => (
        <Stack key={count} gap={3}>
          <Text size="sm" tone="muted">{`columns: ${count}`}</Text>

          <Grid columns={count} gap={4} minItemWidth="xs">
            {METRICS.map((metric) => (
              <Card key={metric.label}>
                <CardBody>
                  <Stack gap={1}>
                    <Text size="sm" tone="muted">
                      {metric.label}
                    </Text>
                    <Heading level={2} size="md">
                      {metric.value}
                    </Heading>
                  </Stack>
                </CardBody>
              </Card>
            ))}
          </Grid>
        </Stack>
      ))}
    </Stack>
  );
}
```

### gap.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const GAPS = [0, 2, 6, 12] as const;

const ORDERS = ['SO-10482', 'SO-10483', 'SO-10484'] as const;

export default function GridGap() {
  return (
    <Stack gap={6}>
      {GAPS.map((gap) => (
        <Stack key={gap} gap={3}>
          <Text size="sm" tone="muted">{`gap: ${gap}`}</Text>

          <Grid columns={3} gap={gap} minItemWidth="xs">
            {ORDERS.map((order) => (
              <Card key={order}>
                <CardBody>
                  <Text numeric="tabular">{order}</Text>
                </CardBody>
              </Card>
            ))}
          </Grid>
        </Stack>
      ))}
    </Stack>
  );
}
```

### justify.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const JUSTIFIES = ['start', 'center', 'end', 'stretch'] as const;

const ACTIONS = ['Ship', 'Hold for review', 'Return to supplier'] as const;

export default function GridJustify() {
  return (
    <Stack gap={6}>
      {JUSTIFIES.map((justify) => (
        <Stack key={justify} gap={3}>
          <Text size="sm" tone="muted">{`justify: ${justify}`}</Text>

          <Grid columns={3} gap={4} justify={justify} minItemWidth="xs">
            {ACTIONS.map((action) => (
              <Card key={action}>
                <CardBody>
                  <Text>{action}</Text>
                </CardBody>
              </Card>
            ))}
          </Grid>
        </Stack>
      ))}
    </Stack>
  );
}
```

### min-item-width.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const WIDTHS = [
  { size: 'xs', rem: '8rem' },
  { size: 'sm', rem: '12rem' },
  { size: 'md', rem: '16rem' },
  { size: 'lg', rem: '20rem' },
  { size: 'xl', rem: '24rem' },
] as const;

const BAYS = ['Bay A1', 'Bay A2', 'Bay B1', 'Bay B2'] as const;

export default function GridMinItemWidth() {
  return (
    <Stack gap={6}>
      {WIDTHS.map((width) => (
        <Stack key={width.size} gap={3}>
          <Text size="sm" tone="muted">{`minItemWidth: ${width.size} (${width.rem})`}</Text>

          <Grid gap={3} minItemWidth={width.size}>
            {BAYS.map((bay) => (
              <Card key={bay}>
                <CardBody>
                  <Text>{bay}</Text>
                </CardBody>
              </Card>
            ))}
          </Grid>
        </Stack>
      ))}
    </Stack>
  );
}
```

### own-width.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Card, CardBody } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

const BAYS = [
  { name: 'Bay 1', status: 'Full', tone: 'success' },
  { name: 'Bay 2', status: 'Half', tone: 'info' },
  { name: 'Bay 3', status: 'Low', tone: 'warning' },
  { name: 'Bay 4', status: 'Empty', tone: 'danger' },
] as const;

const ZONES = ['Zone A', 'Zone B'] as const;

export default function GridOwnWidth() {
  return (
    <Stack gap={6}>
      <Stack gap={3}>
        <Text size="sm" tone="muted">
          Across the whole preview
        </Text>

        <Grid columns={4} gap={4} justify="start" minItemWidth="xs">
          {BAYS.map((bay) => (
            <Badge key={bay.name} tone={bay.tone}>{`${bay.name}: ${bay.status}`}</Badge>
          ))}
        </Grid>
      </Stack>

      <Stack gap={3}>
        <Text size="sm" tone="muted">
          The same grid inside two half-width cards
        </Text>

        <Grid columns={2} gap={6}>
          {ZONES.map((zone) => (
            <Card key={zone}>
              <CardBody>
                <Stack gap={3}>
                  <Heading level={2} size="md">
                    {zone}
                  </Heading>
                  <Grid columns={4} gap={4} justify="start" minItemWidth="xs">
                    {BAYS.map((bay) => (
                      <Badge key={bay.name} tone={bay.tone}>{`${bay.name}: ${bay.status}`}</Badge>
                    ))}
                  </Grid>
                </Stack>
              </CardBody>
            </Card>
          ))}
        </Grid>
      </Stack>
    </Stack>
  );
}
```

### span.tsx

Example

```tsx
import { Field, FieldLabel } from '@slotted/react/field';
import { Grid } from '@slotted/react/grid';
import { TextField } from '@slotted/react/text-field';

export default function GridSpan() {
  return (
    <Grid columns={2} gap={6} minItemWidth="sm">
      <Field style={{ gridColumn: '1 / -1' }}>
        <FieldLabel>Company</FieldLabel>
        <TextField defaultValue="Northwind Traders" />
      </Field>

      <Field>
        <FieldLabel>Contact</FieldLabel>
        <TextField defaultValue="Priya Raman" />
      </Field>

      <Field>
        <FieldLabel>Phone</FieldLabel>
        <TextField defaultValue="+31 10 555 0142" />
      </Field>

      <Field>
        <FieldLabel>City</FieldLabel>
        <TextField defaultValue="Rotterdam" />
      </Field>

      <Field>
        <FieldLabel>Postal code</FieldLabel>
        <TextField defaultValue="3011 AB" />
      </Field>
    </Grid>
  );
}
```
