# Grid Item

Places one child on explicit grid lines with fixed spans and self-alignment.

`GridItem` places a child on explicit grid lines, gives it fixed row or column spans, and controls its self-alignment. It must be used inside a CSS Grid container.

```tsx
import { Center, Grid, GridItem, 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 GridItemExample() {
  return (
    <Grid columns={4} rows={3} gap="3" className="w-full">
      <GridItem column={1} row={1} columnSpan={3}>
        <GridDemoTile>Main content · columns 1–3</GridDemoTile>
      </GridItem>
      <GridItem column={4} row={1} rowSpan={3}>
        <GridDemoTile className="h-full">Sidebar · three rows</GridDemoTile>
      </GridItem>
      <GridItem column={1} row={2} columnSpan={2}>
        <GridDemoTile>Activity</GridDemoTile>
      </GridItem>
      <GridItem column={3} row={2} rowSpan={2}>
        <GridDemoTile className="h-full">Timeline</GridDemoTile>
      </GridItem>
      <GridItem column={1} row={3} columnSpan={2}>
        <GridDemoTile>Reports</GridDemoTile>
      </GridItem>
    </Grid>
  );
}
```

## Import

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

## Placement

`column` and `row` select starting grid lines from 1 through 13 or `auto`. `columnSpan` and `rowSpan` cover 1 through 12 tracks, `full`, or `auto`.

```tsx
<Grid columns={4} rows={3}>
  <GridItem column={1} row={1} columnSpan={3}>
    Main content
  </GridItem>
  <GridItem column={4} row={1} rowSpan={3}>
    Sidebar
  </GridItem>
</Grid>
```

These placement props are intentionally fixed. Use GridSpan when only the span must change across breakpoints, or application-specific classes when explicit starting lines must respond.

## Self-alignment

`alignSelf` moves one item on the block axis and `justifySelf` moves it on the inline axis.

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

function GridItemAlignmentExample() {
  return (
    <Grid
      columns={3}
      rows={2}
      gap="3"
      className="h-64 w-full rounded-xl border border-border bg-background-neutral-card p-3"
    >
      <GridItem column={1} row={1} alignSelf="start" justifySelf="start">
        <Badge>Start</Badge>
      </GridItem>
      <GridItem column={2} row={1} alignSelf="center" justifySelf="center">
        <Badge variant="default" color="information">
          Center
        </Badge>
      </GridItem>
      <GridItem column={3} row={1} alignSelf="end" justifySelf="end">
        <Badge variant="default" color="success">
          End
        </Badge>
      </GridItem>
      <GridItem column={1} row={2} columnSpan={3} alignSelf="stretch" justifySelf="stretch">
        <Center className="h-full rounded-lg border border-border bg-background">
          <Text size="s">Stretch across the assigned area</Text>
        </Center>
      </GridItem>
    </Grid>
  );
}
```

## Polymorphism

GridItem renders a `div` by default. Use `as="li"`, `as="article"`, or another semantic element while retaining placement styles, native props, and the correct ref type.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element. |
| column / row | 1–13 \| auto | — | Starting grid line. |
| columnSpan / rowSpan | 1–12 \| full \| auto | — | Track span. |
| alignSelf | AlignSelf | — | Item alignment on the block axis. |
| justifySelf | JustifySelf | — | Item alignment on the inline axis. |
| 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

CSS placement does not change DOM order. Keep visual order consistent with reading and focus order, especially when manually assigning rows and columns. Do not use grid placement to move a later interactive control ahead of an earlier one visually.

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