LayoutGrid
Searchastronomic.dev# Grid
To set items in even columns, like cards or logos, that drop to fewer columns on small screens.
Static: no JavaScript.
## Usage
```astro
import Grid from "@astronomic-dev/ui/components/Grid.astro";
```
## Examples
### Up to three columns
cols sets the most columns; the Grid shows fewer when it is too narrow for items of at least min.
```astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import Grid from "@astronomic-dev/ui/components/Grid.astro";
const services = [
{ title: "Strategy", text: "We learn your clients, your offer, and what the site must do." },
{ title: "Design", text: "A clear look that fits your firm, tested on real content." },
{ title: "Build", text: "Fast pages, easy editing, and clean handover." },
];
---
<Grid as="ul" role="list" cols={3} class="m-0 list-none p-0">
{
services.map((s) => (
<li class="grid">
<Card>
<h3 class="m-0 text-lg font-semibold">{s.title}</h3>
<p class="m-0 text-muted">{s.text}</p>
</Card>
</li>
))
}
</Grid>
```
### As many as fit
min sets the narrowest an item may be; the Grid fits as many columns as its own width allows.
```astro
---
import Grid from "@astronomic-dev/ui/components/Grid.astro";
const clients = ["Northwind", "Atlas Health", "Fernhollow Savings", "Fieldwork", "Lumen", "Oakline"];
---
<Grid min="9rem" gap="item">
{clients.map((name) => <p class="m-0 rounded-card bg-surface-2 p-4 text-center font-semibold text-muted">{name}</p>)}
</Grid>
```
## Props
### Grid
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `HTMLTag` | `"div"` | The element to render, such as ul. |
| `cols` | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | None | The most columns. The Grid shows fewer when its own width cannot fit that many items of at least `min`, down to one. |
| `min` | `string` | `"15rem"` | The narrowest an item may be, as a CSS length. Without `cols`, as many columns as fit the Grid's own width. |
| `gap` | `"item" \| "blocks" \| "section"` | `"blocks"` | The space between items: a spacing role, set by the preset. |
| `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `default` | The items, one per cell. |
Any other attribute goes on the rendered element. Grid sets --grid-* custom properties in its style; a style you pass is kept with them.
## Accessibility
- Renders a plain <div> with no role, so it adds nothing for a screen reader.
- It never reorders items: the reading order is the source order, row by row.
- For a list of items, use as="ul" with <li> children, and role="list" so the list stays a list without bullets.
Grid
FreeTo set items in even columns, like cards or logos, that drop to fewer columns on small screens.
- File
- Grid.astro
- Group
- Layout
- Kind
- Static: no JavaScript
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Up to three columns
cols sets the most columns; the Grid shows fewer when it is too narrow for items of at least min.
Strategy
We learn your clients, your offer, and what the site must do.
Design
A clear look that fits your firm, tested on real content.
Build
Fast pages, easy editing, and clean handover.
Force statemain.astro
examples/grid/main.astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import Grid from "@astronomic-dev/ui/components/Grid.astro";
const services = [
{ title: "Strategy", text: "We learn your clients, your offer, and what the site must do." },
{ title: "Design", text: "A clear look that fits your firm, tested on real content." },
{ title: "Build", text: "Fast pages, easy editing, and clean handover." },
];
---
<Grid as="ul" role="list" cols={3} class="m-0 list-none p-0">
{
services.map((s) => (
<li class="grid">
<Card>
<h3 class="m-0 text-lg font-semibold">{s.title}</h3>
<p class="m-0 text-muted">{s.text}</p>
</Card>
</li>
))
}
</Grid>As many as fit
min sets the narrowest an item may be; the Grid fits as many columns as its own width allows.
Northwind
Atlas Health
Fernhollow Savings
Fieldwork
Lumen
Oakline
Force statemin.astro
examples/grid/min.astro
---
import Grid from "@astronomic-dev/ui/components/Grid.astro";
const clients = ["Northwind", "Atlas Health", "Fernhollow Savings", "Fieldwork", "Lumen", "Oakline"];
---
<Grid min="9rem" gap="item">
{clients.map((name) => <p class="m-0 rounded-card bg-surface-2 p-4 text-center font-semibold text-muted">{name}</p>)}
</Grid>Minimal · Light