core
Grid
Flexible grid layout with columns, auto-fill, masonry, and responsive collapse
Source
import Markdoc from '@markdoc/markdoc';
const { Tag } = Markdoc;
import { createContentModelSchema, createComponentRenderable, renderNodes } from '../lib/index.js';
import { RenderableNodeCursor } from '../lib/renderable.js';
import { SpaceSeparatedList } from '../attributes.js';
import { flow, GridFlow, gridItems, gridLayout } from '../layouts/index.js';
const GRID_MODES = ['columns', 'auto', 'masonry'];
export const grid = createContentModelSchema({
attributes: {
columns: { type: Number, required: false, description: 'Number of grid columns' },
rows: { type: Number, required: false, description: 'Number of grid rows' },
flow: {
type: String,
required: false,
matches: flow.slice(),
description: 'Direction items fill the grid',
},
spans: {
type: SpaceSeparatedList,
required: false,
description: 'Column span widths for each cell (space-separated)',
},
ratio: { type: String, required: false, description: 'Column width ratio (e.g. "2 1 1")' },
gap: {
type: String,
required: false,
matches: ['none', 'tight', 'default', 'loose'],
description: 'Space between grid cells',
},
valign: {
type: String,
required: false,
matches: ['top', 'center', 'bottom', 'stretch', 'baseline'],
description: 'Vertical alignment of cell content',
},
collapse: {
type: String,
required: false,
matches: ['sm', 'md', 'lg', 'never'],
description: 'Breakpoint at which grid collapses to a single column',
},
mode: {
type: String,
required: false,
matches: ['columns', 'auto', 'masonry'],
default: 'columns',
description: 'Grid sizing: fixed columns, auto-fit, or masonry',
},
min: { type: String, required: false, description: 'Minimum cell width for auto-fit mode' },
aspect: { type: String, required: false, description: 'Aspect ratio for grid cells' },
stack: {
type: String,
required: false,
matches: ['natural', 'reverse'],
description: 'Stacking order when collapsed',
},
},
contentModel: {
type: 'delimited',
delimiter: 'hr',
dynamicZones: true,
zoneModel: {
type: 'sequence',
fields: [{ name: 'content', match: 'any', greedy: true, optional: true }],
},
},
deprecations: {
layout: {
newName: 'spans',
transform: (val: any, attrs: Record<string, any>) => {
if (typeof val === 'string' && GRID_MODES.includes(val)) {
attrs.mode = val;
return undefined;
}
return val;
},
},
},
transform(resolved, attrs, config) {
const zones = (resolved.zones ?? []) as Array<Record<string, unknown>>;
const tiles = zones.map((zone) => renderNodes(zone.content, config));
const layout = gridLayout({
items: gridItems(attrs.spans as string[], tiles),
rows: attrs.rows as number | undefined,
columns: attrs.columns as number | undefined,
flow: attrs.flow as GridFlow,
});
const ratioMeta = attrs.ratio ? new Tag('meta', { content: attrs.ratio }) : undefined;
const gapMeta =
attrs.gap && attrs.gap !== 'default' ? new Tag('meta', { content: attrs.gap }) : undefined;
const valignMeta = attrs.valign ? new Tag('meta', { content: attrs.valign }) : undefined;
const collapseMeta = attrs.collapse ? new Tag('meta', { content: attrs.collapse }) : undefined;
const modeMeta =
attrs.mode && attrs.mode !== 'columns' ? new Tag('meta', { content: attrs.mode }) : undefined;
const minMeta = attrs.min ? new Tag('meta', { content: attrs.min }) : undefined;
const aspectMeta = attrs.aspect ? new Tag('meta', { content: attrs.aspect }) : undefined;
const stackMeta = attrs.stack ? new Tag('meta', { content: attrs.stack }) : undefined;
return createComponentRenderable({
rune: 'grid',
tag: 'section',
children: [layout],
properties: {
mode: modeMeta,
ratio: ratioMeta,
gap: gapMeta,
valign: valignMeta,
collapse: collapseMeta,
min: minMeta,
aspect: aspectMeta,
stack: stackMeta,
},
refs: {
cell: new RenderableNodeCursor(layout.children).tag('div'),
},
});
},
});
Flexible grid layout. Children separated by horizontal rules (---) become cells arranged in a responsive CSS grid. Supports explicit column spans, auto-fill mode, masonry, aspect ratio enforcement, and responsive collapse. For a set of images with captions and a lightbox, use gallery.
Basic usage
Equal columns created by separating content with horizontal rules.
{% grid %}
**Opening hours.** Daily 9:00–18:00, with late opening until 21:00 on Fridays in summer.
---
**Getting there.** Tram 4 to Garden Gate, or a ten-minute walk from the central station.
---
**Tickets.** Adults €12, under-16s free. Members skip the queue at the east entrance.
{% /grid %}<section data-rune="grid">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Opening hours.</strong>
Daily 9:00–18:00, with late opening until 21:00 on Fridays in summer.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Getting there.</strong>
Tram 4 to Garden Gate, or a ten-minute walk from the central station.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Tickets.</strong>
Adults €12, under-16s free. Members skip the queue at the east entrance.
</p>
</div>
</div>
</section>Opening hours. Daily 9:00–18:00, with late opening until 21:00 on Fridays in summer.
Getting there. Tram 4 to Garden Gate, or a ten-minute walk from the central station.
Tickets. Adults €12, under-16s free. Members skip the queue at the east entrance.
<section class="rf-grid rf-grid--columns" data-mode="columns" data-rune="grid" data-density="full">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Opening hours.</strong>
Daily 9:00–18:00, with late opening until 21:00 on Fridays in summer.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Getting there.</strong>
Tram 4 to Garden Gate, or a ten-minute walk from the central station.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Tickets.</strong>
Adults €12, under-16s free. Members skip the queue at the east entrance.
</p>
</div>
</div>
</section>How Markdown is read
| You write | It becomes |
|---|---|
--- (a horizontal rule) | The boundary between two cells |
| The content between rules | One cell, kept as written: text, images, lists or other runes |
Unequal columns
Use the spans attribute to control column widths. Values are space-separated span sizes.
{% grid spans="2 1" %}
**The glasshouses.** Three Victorian glasshouses hold the garden's tropical, desert and alpine collections. The palm house is the oldest, built in 1868 and restored in 2019.
---
**Allow an hour** for all three.
{% /grid %}<section data-rune="grid">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">The glasshouses.</strong>
Three Victorian glasshouses hold the garden's tropical, desert and alpine collections. The palm house is the oldest, built in 1868 and restored in 2019.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Allow an hour</strong>
for all three.
</p>
</div>
</div>
</section>The glasshouses. Three Victorian glasshouses hold the garden's tropical, desert and alpine collections. The palm house is the oldest, built in 1868 and restored in 2019.
Allow an hour for all three.
<section class="rf-grid rf-grid--columns" data-mode="columns" data-rune="grid" data-density="full">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">The glasshouses.</strong>
Three Victorian glasshouses hold the garden's tropical, desert and alpine collections. The palm house is the oldest, built in 1868 and restored in 2019.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Allow an hour</strong>
for all three.
</p>
</div>
</div>
</section>Gap
Control spacing between cells with the gap attribute.
{% grid gap="tight" %}
**Café** — east lawn
---
**Shop** — main gate
---
**Toilets** — by the palm house
{% /grid %}<section data-rune="grid" data-rune-fields="{"gap":"tight"}">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Café</strong>
— east lawn
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Shop</strong>
— main gate
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Toilets</strong>
— by the palm house
</p>
</div>
</div>
</section>Café — east lawn
Shop — main gate
Toilets — by the palm house
<section class="rf-grid rf-grid--columns" data-mode="columns" data-gap="tight" data-rune="grid" data-density="full" style="--grid-gap: var(--rf-spacing-sm)">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Café</strong>
— east lawn
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Shop</strong>
— main gate
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Toilets</strong>
— by the palm house
</p>
</div>
</div>
</section>Alignment
Vertically align cells within their row using the valign attribute. Useful when cells have different heights.
{% grid valign="center" spans="2 1" %}
**Guided walks.** A volunteer guide leads a one-hour walk through the seasonal highlights, starting at the main gate.
Walks run at 11:00 and 14:00 every day except Monday, and are included in the ticket price.
---
**Free** — no booking needed.
{% /grid %}<section data-rune="grid" data-rune-fields="{"valign":"center"}">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">Guided walks.</strong>
A volunteer guide leads a one-hour walk through the seasonal highlights, starting at the main gate.
</p>
<p>Walks run at 11:00 and 14:00 every day except Monday, and are included in the ticket price.</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Free</strong>
— no booking needed.
</p>
</div>
</div>
</section>Guided walks. A volunteer guide leads a one-hour walk through the seasonal highlights, starting at the main gate.
Walks run at 11:00 and 14:00 every day except Monday, and are included in the ticket price.
Free — no booking needed.
<section class="rf-grid rf-grid--columns" data-mode="columns" data-valign="center" data-rune="grid" data-density="full" style="--grid-valign: center">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">Guided walks.</strong>
A volunteer guide leads a one-hour walk through the seasonal highlights, starting at the main gate.
</p>
<p>Walks run at 11:00 and 14:00 every day except Monday, and are included in the ticket price.</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Free</strong>
— no booking needed.
</p>
</div>
</div>
</section>Responsive collapse
Force the grid to collapse to a single column at a given breakpoint: sm (640px), md (768px), lg (1024px), or never.
{% grid collapse="md" %}
**Plan your visit.** Hours, tickets and accessibility information.
---
**What's in bloom.** Magnolias in the spring walk, and the first alpine gentians.
{% /grid %}<section data-rune="grid" data-rune-fields="{"collapse":"md"}">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Plan your visit.</strong>
Hours, tickets and accessibility information.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">What's in bloom.</strong>
Magnolias in the spring walk, and the first alpine gentians.
</p>
</div>
</div>
</section>Plan your visit. Hours, tickets and accessibility information.
What's in bloom. Magnolias in the spring walk, and the first alpine gentians.
<section class="rf-grid rf-grid--columns" data-mode="columns" data-collapse="md" data-rune="grid" data-density="full">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Plan your visit.</strong>
Hours, tickets and accessibility information.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">What's in bloom.</strong>
Magnolias in the spring walk, and the first alpine gentians.
</p>
</div>
</div>
</section>Auto mode
Responsive auto-fill layout. The grid creates as many columns as fit, each at least min wide. No explicit column count needed.
{% grid mode="auto" min="200px" %}
**Palm house**
---
**Desert house**
---
**Alpine house**
---
**Rose garden**
{% /grid %}<section data-rune="grid" data-rune-fields="{"mode":"auto","min":"200px"}">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Palm house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Desert house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Alpine house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Rose garden</strong>
</p>
</div>
</div>
</section>Palm house
Desert house
Alpine house
Rose garden
<section class="rf-grid rf-grid--auto" data-mode="auto" data-min="200px" data-rune="grid" data-density="full" style="--grid-min: 200px">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Palm house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Desert house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Alpine house</strong>
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Rose garden</strong>
</p>
</div>
</div>
</section>Masonry mode
Progressive enhancement for masonry-style layouts. Falls back to a standard grid in browsers that don't support CSS masonry.
{% grid mode="masonry" columns=3 %}
**Rose garden.** 400 varieties.
---
**Arboretum.** Oaks, limes and a 200-year-old cedar of Lebanon, planted when the garden was still a private estate. The cedar's lowest branch is propped on a timber crutch.
---
**Pond.** Water lilies from June.
---
**Herb garden.** Medicinal and kitchen herbs, labelled with their traditional uses.
{% /grid %}<section data-rune="grid" data-rune-fields="{"mode":"masonry"}">
<div data-layout="grid" data-columns="3">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Rose garden.</strong>
400 varieties.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Arboretum.</strong>
Oaks, limes and a 200-year-old cedar of Lebanon, planted when the garden was still a private estate. The cedar's lowest branch is propped on a timber crutch.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Pond.</strong>
Water lilies from June.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Herb garden.</strong>
Medicinal and kitchen herbs, labelled with their traditional uses.
</p>
</div>
</div>
</section>Rose garden. 400 varieties.
Arboretum. Oaks, limes and a 200-year-old cedar of Lebanon, planted when the garden was still a private estate. The cedar's lowest branch is propped on a timber crutch.
Pond. Water lilies from June.
Herb garden. Medicinal and kitchen herbs, labelled with their traditional uses.
<section class="rf-grid rf-grid--masonry" data-mode="masonry" data-rune="grid" data-density="full">
<div data-layout="grid" data-columns="3">
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Rose garden.</strong>
400 varieties.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Arboretum.</strong>
Oaks, limes and a 200-year-old cedar of Lebanon, planted when the garden was still a private estate. The cedar's lowest branch is propped on a timber crutch.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Pond.</strong>
Water lilies from June.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Herb garden.</strong>
Medicinal and kitchen herbs, labelled with their traditional uses.
</p>
</div>
</div>
</section>Aspect ratio
Enforce a uniform aspect ratio on all grid cells. Content is cropped with object-fit: cover — ideal for image galleries.
{% grid mode="auto" min="200px" aspect="1/1" %}

---

---

{% /grid %}<section data-rune="grid" data-rune-fields="{"mode":"auto","min":"200px","aspect":"1/1"}">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-old-growth.jpg" alt="Moss-covered trunks in an old-growth forest">
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-valley.jpg" alt="A river winding through a green valley">
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-zen-garden.jpg" alt="Raked gravel and stones in a zen garden">
</p>
</div>
</div>
</section>


<section class="rf-grid rf-grid--auto" data-mode="auto" data-aspect="1/1" data-min="200px" data-rune="grid" data-density="full" style="--grid-min: 200px; --grid-aspect: 1/1">
<div data-layout="grid">
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-old-growth.jpg" alt="Moss-covered trunks in an old-growth forest" />
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-valley.jpg" alt="A river winding through a green valley" />
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<img src="https://assets.refrakt.md/media-text-zen-garden.jpg" alt="Raked gravel and stones in a zen garden" />
</p>
</div>
</div>
</section>Stack order
Control the order of cells when the grid collapses to a single column on mobile. By default cells stack in source order; stack="reverse" places the last cell first.
{% grid spans="2 1" collapse="md" stack="reverse" %}
**Today's events.** Guided walk at 11:00, bee-keeping talk at 15:00 in the education centre.
---
**Closing early** at 16:00 today for a private event.
{% /grid %}<section data-rune="grid" data-rune-fields="{"collapse":"md","stack":"reverse"}">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">Today's events.</strong>
Guided walk at 11:00, bee-keeping talk at 15:00 in the education centre.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Closing early</strong>
at 16:00 today for a private event.
</p>
</div>
</div>
</section>Today's events. Guided walk at 11:00, bee-keeping talk at 15:00 in the education centre.
Closing early at 16:00 today for a private event.
<section class="rf-grid rf-grid--columns" data-mode="columns" data-collapse="md" data-stack="reverse" data-rune="grid" data-density="full">
<div data-layout="grid">
<div data-colspan="2" data-name="cell">
<p>
<strong marker="**">Today's events.</strong>
Guided walk at 11:00, bee-keeping talk at 15:00 in the education centre.
</p>
</div>
<div data-colspan="1" data-name="cell">
<p>
<strong marker="**">Closing early</strong>
at 16:00 today for a private event.
</p>
</div>
</div>
</section>Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
columns | number | — | Number of grid columns |
rows | number | — | Number of grid rows |
flow | "row" | "column" | "dense" | "row dense" | "column dense" | — | Direction items fill the grid |
spans | SpaceSeparatedList | — | Column span widths for each cell (space-separated) |
ratio | string | — | Column width ratio (e.g. "2 1 1") |
gap | "none" | "tight" | "default" | "loose" | — | Space between grid cells |
valign | "top" | "center" | "bottom" | "stretch" | "baseline" | — | Vertical alignment of cell content |
collapse | "sm" | "md" | "lg" | "never" | — | Breakpoint at which grid collapses to a single column |
mode | "columns" | "auto" | "masonry" | — | Grid sizing: fixed columns, auto-fit, or masonry |
min | string | — | Minimum cell width for auto-fit mode |
aspect | string | — | Aspect ratio for grid cells |
stack | "natural" | "reverse" | — | Stacking order when collapsed |
layout | SpaceSeparatedList | — |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |