> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/grid.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Grid

Lays out content in columns and rows, or in a single flex row for toolbars.

{% code title="grid/demo.tsx" %}

```tsx
import { Grid, TextField } from "@rierino-open/core-ui";

const label = { fontSize: 12, fontWeight: 600, alignSelf: "center" } as const;

export default function GridDemo() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Grid columns={12} gap={3}>
        <Grid.Item xs={12} sm={4} style={label}>Name</Grid.Item>
        <Grid.Item xs={12} sm={8}>
          <TextField aria-label="Name" initialValue="Linen shirt" />
        </Grid.Item>

        <Grid.Item xs={12} sm={4} style={label}>SKU</Grid.Item>
        <Grid.Item xs={12} sm={8}>
          <TextField aria-label="SKU" initialValue="LS-2041" />
        </Grid.Item>
      </Grid>
    </div>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Grid } from '@rierino-open/core-ui';

<Grid columns={12} gap={3}>
  <Grid.Item xs={12} sm={4}>Name</Grid.Item>
  <Grid.Item xs={12} sm={8}>…</Grid.Item>
</Grid>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Grid } = CoreUI;

<Grid columns={12} gap={3}>
  <Grid.Item xs={12} sm={4}>Name</Grid.Item>
  <Grid.Item xs={12} sm={8}>…</Grid.Item>
</Grid>
```

{% endtab %}
{% endtabs %}

`Grid` is a CSS grid. Its direct children are the cells. Wrap a child in `Grid.Item` when it should span several columns or rows; any other element takes one cell.

The example above is the layout Rierino forms use: a 12-column grid where the label takes 4 columns and the input 8 on wider screens, and both take the full width on narrow ones.

## Examples

### Columns

`columns` sets the number of equal columns, from 1 to 12. Items fill them left to right and wrap onto new rows.

{% code title="grid/columns.tsx" %}

```tsx
import { Grid } from "@rierino-open/core-ui";

const cell = {
  padding: 12,
  borderRadius: 6,
  background: "#F4F0FF",
  color: "#6022F1",
  fontSize: 12,
  textAlign: "center",
} as const;

export default function GridColumns() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Grid columns={3} gap={3}>
        {[1, 2, 3, 4, 5, 6].map((n) => (
          <div key={n} style={cell}>
            {n}
          </div>
        ))}
      </Grid>
    </div>
  );
}
```

{% endcode %}

### Spanning columns

`Grid.Item` with `colSpan` takes several columns. In a 12-column grid, spans that add up to 12 fill a row. `full` spans every column.

{% code title="grid/spans.tsx" %}

```tsx
import { Grid } from "@rierino-open/core-ui";

const cell = {
  padding: 12,
  borderRadius: 6,
  background: "#F4F0FF",
  color: "#6022F1",
  fontSize: 12,
  textAlign: "center",
} as const;

export default function GridSpans() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Grid columns={12} gap={3}>
        <Grid.Item colSpan={8} style={cell}>colSpan 8</Grid.Item>
        <Grid.Item colSpan={4} style={cell}>4</Grid.Item>
        <Grid.Item colSpan={6} style={cell}>6</Grid.Item>
        <Grid.Item colSpan={6} style={cell}>6</Grid.Item>
        <Grid.Item colSpan="full" style={cell}>full</Grid.Item>
      </Grid>
    </div>
  );
}
```

{% endcode %}

### Responsive layouts

Pass an object to `columns` to change it at a breakpoint: `initial` applies at every width, and `sm`, `md`, `lg`, `xl` and `2xl` apply from that width up. On `Grid.Item`, use the `xs`, `sm`, `md`, `lg` and `xl` props to change the span the same way.

{% code title="grid/responsive.tsx" %}

```tsx
import { Grid } from "@rierino-open/core-ui";

const cell = {
  padding: 12,
  borderRadius: 6,
  background: "#F4F0FF",
  color: "#6022F1",
  fontSize: 12,
  textAlign: "center",
} as const;

export default function GridResponsive() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      {/* One column on phones, three from sm (640px) up. */}
      <Grid columns={{ initial: 1, sm: 3 }} gap={3}>
        <div style={cell}>Details</div>
        <div style={cell}>Pricing</div>
        <div style={cell}>Stock</div>
      </Grid>
    </div>
  );
}
```

{% endcode %}

| Breakpoint | Applies from |
| ---------- | ------------ |
| `sm`       | 640px        |
| `md`       | 768px        |
| `lg`       | 1024px       |
| `xl`       | 1280px       |
| `2xl`      | 1536px       |

{% hint style="info" %}
**Breakpoints follow the window, not the container**

Breakpoints compare against the browser window's width. In the admin UI, a grid inside a panel or dialog is narrower than the window, so a `md` layout can apply to a container that is much narrower than 768px. Check your layout at the size it is actually shown.
{% endhint %}

### Gaps

`gap` sets the space between cells, on Tailwind's spacing scale: `1` is 4px, `2` is 8px, `4` is 16px, up to `24`. `gapX` and `gapY` set the space between columns and between rows separately.

{% code title="grid/gaps.tsx" %}

```tsx
import { Grid } from "@rierino-open/core-ui";

const cell = {
  padding: 12,
  borderRadius: 6,
  background: "#F4F0FF",
  color: "#6022F1",
  fontSize: 12,
  textAlign: "center",
} as const;

export default function GridGaps() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Grid columns={4} gapX={8} gapY={2}>
        {[1, 2, 3, 4, 5, 6, 7, 8].map((n) => (
          <div key={n} style={cell}>
            {n}
          </div>
        ))}
      </Grid>
    </div>
  );
}
```

{% endcode %}

If you set only `gapX`, it applies to rows as well. Add `gapY` (it can be `0`) to set the row gap separately.

### Placing items

`colStart` and `colEnd` place an item between column lines, and `rowSpan`, `rowStart` and `rowEnd` do the same for rows. Lines are numbered from 1, so in a 4-column grid the last line is 5.

{% code title="grid/placement.tsx" %}

```tsx
import { Grid } from "@rierino-open/core-ui";

const cell = {
  padding: 12,
  borderRadius: 6,
  background: "#F4F0FF",
  color: "#6022F1",
  fontSize: 12,
  textAlign: "center",
} as const;

export default function GridPlacement() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Grid columns={4} gap={3}>
        <Grid.Item rowSpan={2} style={{ ...cell, display: "grid", placeItems: "center" }}>
          rowSpan 2
        </Grid.Item>
        <Grid.Item colStart={3} colSpan={2} style={cell}>
          colStart 3, colSpan 2
        </Grid.Item>
        <Grid.Item colSpan={3} style={cell}>
          colSpan 3
        </Grid.Item>
      </Grid>
    </div>
  );
}
```

{% endcode %}

### Toolbars with flex

`flex` turns the grid into a single flex row, which is the usual way to lay out a toolbar or a row of buttons. With `flow="col"`, the items stack vertically. `columns` and the span props have no effect in flex mode.

{% code title="grid/flex.tsx" %}

```tsx
import { Button, Grid } from "@rierino-open/core-ui";

export default function GridFlex() {
  return (
    <div style={{ display: "grid", gap: 24 }}>
      {/* A toolbar: buttons side by side. */}
      <Grid flex gap={2}>
        <Grid.Item>
          <Button intent="g-button">Save</Button>
        </Grid.Item>
        <Grid.Item>
          <Button appearance="outline">Preview</Button>
        </Grid.Item>
        <Grid.Item>
          <Button appearance="plain">Cancel</Button>
        </Grid.Item>
      </Grid>

      {/* flow="col" stacks them instead. */}
      <Grid flex flow="col" gap={2}>
        <Button appearance="outline">Duplicate</Button>
        <Button appearance="outline">Archive</Button>
      </Grid>
    </div>
  );
}
```

{% endcode %}

## Accessibility

Grid is a layout container: it renders plain `<div>` elements with no role, so it doesn't change how content is announced. Screen readers and keyboard focus follow the order of the children in the code, not their visual position, so keep that order meaningful when you move items with `colStart` or `rowStart`.

## Styling

`className` and other HTML attributes, such as `style` and `id`, are passed to the grid's `<div>`. Each `Grid.Item` carries the `grid-cell` class, so you can style every cell of a grid at once:

```css
.Rie-Pricing-grid > .grid-cell {
  padding: 8px;
  border-bottom: 1px solid var(--color-athens-gray);
}
```

Tailwind classes in `className` override the matching Grid prop, so `className="grid-cols-6"` beats `columns={2}`.

## API reference

### Grid

| Prop        | Type                                                                                                 | Default | Description                                                                                                                     |
| ----------- | ---------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `columns`   | `1–12 \| { initial, sm, … }`                                                                         | `1`     | The number of columns, 1 to 12, or an object with a value per breakpoint, such as `{ initial: 1, md: 3 }`. Ignored with `flex`. |
| `rows`      | `1–12 \| { initial, sm, … }`                                                                         |         | The number of explicit rows, 1 to 12. Extra items flow into new rows automatically.                                             |
| `gap`       | `0 \| 0.5 \| 1 \| 1.5 \| 2 \| 2.5 \| 3 \| 3.5 \| 4–12 \| 14 \| 16 \| 20 \| 24 \| { initial, sm, … }` |         | The space between cells in both directions, on Tailwind's spacing scale (`1` is 4px, `4` is 16px), from 0 to 24.                |
| `gapX`      | `0 \| 0.5 \| 1 \| 1.5 \| 2 \| 2.5 \| 3 \| 3.5 \| 4–12 \| 14 \| 16 \| 20 \| 24 \| { initial, sm, … }` |         | The space between columns. Without `gap` or `gapY`, it also sets the space between rows.                                        |
| `gapY`      | `0 \| 0.5 \| 1 \| 1.5 \| 2 \| 2.5 \| 3 \| 3.5 \| 4–12 \| 14 \| 16 \| 20 \| 24 \| { initial, sm, … }` |         | The space between rows.                                                                                                         |
| `flow`      | `"col" \| "colDense" \| "dense" \| "row" \| "rowDense" \| { initial, sm, … }`                        | `"row"` | The direction items are placed in. With `flex`, `row` lays them out side by side and `col` stacks them.                         |
| `flex`      | `boolean \| { initial, sm, … }`                                                                      |         | Lays the children out in a single flex row (or column, with `flow="col"`) instead of a grid.                                    |
| `className` | `string`                                                                                             |         |                                                                                                                                 |

### Grid.Item

| Prop        | Type                                             | Default | Description                                                                                           |
| ----------- | ------------------------------------------------ | ------- | ----------------------------------------------------------------------------------------------------- |
| `colSpan`   | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | How many columns the item spans: 1 to 12, `full` or `auto`, or an object with a value per breakpoint. |
| `xs`        | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | Columns spanned at every width. The same as `colSpan`.                                                |
| `sm`        | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | Columns spanned from the `sm` breakpoint (640px) up. Overrides `colSpan` and `xs`.                    |
| `md`        | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | Columns spanned from the `md` breakpoint (768px) up.                                                  |
| `lg`        | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | Columns spanned from the `lg` breakpoint (1024px) up.                                                 |
| `xl`        | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | Columns spanned from the `xl` breakpoint (1280px) up.                                                 |
| `colStart`  | `"auto" \| 1–13 \| { initial, sm, … }`           |         | The column line the item starts at, 1 to 13.                                                          |
| `colEnd`    | `"auto" \| 1–13 \| { initial, sm, … }`           |         | The column line the item ends at, 1 to 13.                                                            |
| `rowSpan`   | `"auto" \| "full" \| 1–12 \| { initial, sm, … }` |         | How many rows the item spans: 1 to 12, `full` or `auto`.                                              |
| `rowStart`  | `"auto" \| 1–13 \| { initial, sm, … }`           |         | The row line the item starts at, 1 to 13.                                                             |
| `rowEnd`    | `"auto" \| 1–13 \| { initial, sm, … }`           |         | The row line the item ends at, 1 to 13.                                                               |
| `className` | `string`                                         |         |                                                                                                       |

Both also accept the HTML attributes of a `<div>`, such as `style`, `id` and event handlers.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/grid.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
