# Grid

A responsive CSS Grid container with typed tracks, gaps, alignment, and auto-flow.

`Grid` creates responsive two-dimensional layouts with typed track counts and spacing. It controls the grid container; use GridItem or GridSpan when a child needs explicit placement or spanning.

```tsx
import { Grid, Stack, Text } from "@zentara-co/zenos-ui";

function GridExample() {
  return (
    <Grid columns={{ base: 1, md: 2, lg: 4 }} gap={{ base: "3", lg: "4" }} className="w-full">
      {["Assets", "Findings", "Coverage", "Members"].map((label, index) => (
        <Stack
          key={label}
          gap="2"
          className="rounded-xl border border-border bg-background-neutral-card p-4"
        >
          <Text size="s" color="subtle">
            {label}
          </Text>
          <Text as="p" type="heading" size="h4">
            {[128, 7, 94, 24][index]}
          </Text>
        </Stack>
      ))}
    </Grid>
  );
}
```

## Import

```tsx
import { Grid } from "@zentara-co/zenos-ui";
```

## Tracks and gaps

`columns` and `rows` accept responsive counts from 1 through 12. `gap` sets both axes, while `columnGap` and `rowGap` refine each axis independently.

```tsx
import { Center, Grid, Text } from "@zentara-co/zenos-ui";
import { type ReactNode } from "react";

function GridDemoTile({ children, className }: { children: ReactNode; className?: string }) {
  return (
    <Center
      minHeight="20"
      padding="3"
      className={`rounded-lg border border-border bg-background-neutral-card ${className ?? ""}`}
    >
      <Text size="s" weight="bold" align="center">
        {children}
      </Text>
    </Center>
  );
}

function GridTracksExample() {
  return (
    <Grid
      columns={{ base: 2, md: 3 }}
      rows={2}
      columnGap={{ base: "2", md: "4" }}
      rowGap="6"
      className="w-full"
    >
      {Array.from({ length: 6 }, (_, index) => (
        <GridDemoTile key={index}>Track {index + 1}</GridDemoTile>
      ))}
    </Grid>
  );
}
```

## Auto flow

`autoFlow` controls how auto-positioned children fill explicit tracks. It is a direct value rather than a responsive prop.

```tsx
import { Center, Grid, Text } from "@zentara-co/zenos-ui";
import { type ReactNode } from "react";

function GridDemoTile({ children, className }: { children: ReactNode; className?: string }) {
  return (
    <Center
      minHeight="20"
      padding="3"
      className={`rounded-lg border border-border bg-background-neutral-card ${className ?? ""}`}
    >
      <Text size="s" weight="bold" align="center">
        {children}
      </Text>
    </Center>
  );
}

function GridAutoFlowExample() {
  return (
    <Grid columns={3} rows={2} autoFlow="column" gap="3" className="w-full">
      {Array.from({ length: 6 }, (_, index) => (
        <GridDemoTile key={index}>Item {index + 1}</GridDemoTile>
      ))}
    </Grid>
  );
}
```

Use `dense`, `row-dense`, or `column-dense` carefully: dense packing may make visual order differ from source order.

## Alignment

`align` controls how items sit on the block axis of their cells. `justify` distributes the grid content on the inline axis. Both accept responsive values. Use GridItem's self-alignment props when only one child differs.

## Semantics

Grid renders a `div` by default. Use `as="ul"` with list-item children for a semantic collection, or another element that matches the content. Grid styles do not remove native list or landmark semantics.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element. |
| columns / rows | Responsive<1 \| 2 \| ... \| 12> | columns: 1 | Responsive explicit grid track counts. |
| gap | Responsive<Spacing> | 4 | Shared row and column gap. |
| columnGap / rowGap | Responsive<Spacing> | — | Axis-specific gap overrides. |
| align / justify | Responsive<Align \| Justify> | — | Grid item alignment and content distribution. |
| autoFlow | row \| column \| dense \| row-dense \| column-dense | — | Placement direction for auto-positioned items. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Keep DOM order aligned with the intended reading and keyboard order. Explicit placement and dense flow can rearrange visuals without rearranging the accessibility tree. Test responsive layouts at narrow widths, 200% zoom, and with keyboard focus visible.

Source: https://zenos-ui.pages.dev/layout/grid/