core
Card
A generic, self-contained content card — optional media, body, and footer zones, with an optional whole-card link
Source
import Markdoc from '@markdoc/markdoc';
import type { Node, RenderableTreeNode } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
createContentModelSchema,
bodyOnly,
createComponentRenderable,
asNodes,
} from '../lib/index.js';
import { RenderableNodeCursor } from '../lib/renderable.js';
import {
SplitLayoutModel,
buildLayoutMetas,
splitMediaBodyFooter,
extractMediaImage,
stretchedLink,
} from './common.js';
export const cardSections = { media: 'media', eyebrow: 'eyebrow', body: 'body' } as const;
export const card = createContentModelSchema({
sections: cardSections,
provides: ['prose'],
base: SplitLayoutModel,
attributes: {
href: {
type: String,
required: false,
default: '',
description: 'Optional link target; makes the whole card clickable.',
},
'content-place': {
type: String,
required: false,
description: 'Cover overlay anchor: "<block> <inline>" (e.g. "end start") or "auto"',
},
height: {
type: String,
required: false,
matches: ['sm', 'md', 'lg', 'xl'],
description: 'Intrinsic card height (named scale) for cover / bg-only cards',
},
aspect: {
type: String,
required: false,
description: 'Intrinsic card aspect ratio (e.g. "16/9", "3/4") for cover / bg-only cards',
},
},
contentModel: bodyOnly(),
transform(resolved, attrs, config) {
const {
media: mediaNodes,
body: bodyNodes,
footer: footerNodes,
} = splitMediaBodyFooter(asNodes(resolved.body));
const { metas: layoutMetas, children: layoutChildren } = buildLayoutMetas(attrs);
const contentPlace = attrs['content-place'] as string | undefined;
const height = attrs.height as string | undefined;
const aspect = attrs.aspect as string | undefined;
const contentPlaceMeta = contentPlace ? new Tag('meta', { content: contentPlace }) : undefined;
const heightMeta = height ? new Tag('meta', { content: height }) : undefined;
const aspectMeta = aspect ? new Tag('meta', { content: aspect }) : undefined;
const children: RenderableTreeNode[] = layoutChildren.filter(
(c) => c !== layoutMetas.mediaPosition,
);
if (mediaNodes.length > 0) {
const mediaCursor = new RenderableNodeCursor(
Markdoc.transform(mediaNodes, config) as RenderableTreeNode[],
);
const img = extractMediaImage(mediaCursor);
const inner = img ? [img] : mediaCursor.toArray();
children.push(
new Tag(
'div',
{ 'data-section': 'media', 'data-name': 'media' },
inner as RenderableTreeNode[],
),
);
}
let eyebrowNode: Node | undefined;
let mainBodyNodes = bodyNodes;
if (
bodyNodes.length >= 2 &&
bodyNodes[0].type === 'paragraph' &&
bodyNodes[1].type === 'heading'
) {
eyebrowNode = bodyNodes[0];
mainBodyNodes = bodyNodes.slice(1);
}
let eyebrowTag: InstanceType<typeof Tag> | undefined;
if (eyebrowNode) {
const eyebrowCursor = new RenderableNodeCursor(
Markdoc.transform([eyebrowNode], config) as RenderableTreeNode[],
);
const first = eyebrowCursor.toArray()[0];
if (Markdoc.Tag.isTag(first)) {
eyebrowTag = first;
}
}
const bodyCursor = new RenderableNodeCursor(
Markdoc.transform(mainBodyNodes, config) as RenderableTreeNode[],
);
const bodyRendered = bodyCursor.toArray() as RenderableTreeNode[];
const titleTag = bodyRendered.find(
(n): n is InstanceType<typeof Tag> => Markdoc.Tag.isTag(n) && /^h[1-6]$/.test(n.name),
);
const bodyDiv = new Tag('div', { 'data-name': 'body' }, bodyRendered);
let footerTag: InstanceType<typeof Tag> | undefined;
if (footerNodes.length > 0) {
const footerCursor = new RenderableNodeCursor(
Markdoc.transform(footerNodes, config) as RenderableTreeNode[],
);
footerTag = new Tag(
'footer',
{ 'data-name': 'footer' },
footerCursor.toArray() as RenderableTreeNode[],
);
}
if (eyebrowTag) children.push(eyebrowTag);
children.push(bodyDiv);
if (footerTag) children.push(footerTag);
let linkTag: InstanceType<typeof Tag> | undefined;
const href = String(attrs.href ?? '');
if (href) {
linkTag = stretchedLink(href);
children.push(linkTag);
}
const refs: Record<string, InstanceType<typeof Tag>> = { body: bodyDiv };
if (titleTag) refs.title = titleTag;
if (eyebrowTag) refs.eyebrow = eyebrowTag;
if (footerTag) refs.footer = footerTag;
if (linkTag) refs.link = linkTag;
return createComponentRenderable({
rune: 'card',
tag: 'div',
properties: {
'media-position': layoutMetas.mediaPosition,
'content-place': contentPlaceMeta,
height: heightMeta,
aspect: aspectMeta,
},
refs,
children,
});
},
});
A self-contained tile: a bordered surface with an optional media zone, a body, and an optional footer. Use it on its own in prose, or as the body template of a collection to list entities; there is one card for every kind of item, rather than a card rune per type. To give a block of content a headline and intro without framing it as a tile, use section.
Basic usage
{% card %}
---
### Valley loop
Nine kilometres along the river and back over the ridge, with a café at the halfway bridge.
---
Walk · Moderate · 3 hours
{% /card %}<div data-rune="card" data-rune-fields="{"media-position":"top"}">
<div data-name="body">
<h3 id="valley-loop" data-name="title">Valley loop</h3>
<p>Nine kilometres along the river and back over the ridge, with a café at the halfway bridge.</p>
</div>
<footer data-name="footer">
<p>Walk · Moderate · 3 hours</p>
</footer>
</div>Valley loop
Nine kilometres along the river and back over the ridge, with a café at the halfway bridge.
<div class="rf-card" data-media-position="top" data-rune="card" data-density="full">
<div data-name="content" class="rf-card__content">
<div data-name="body" class="rf-card__body" data-section="body">
<h3 id="valley-loop" data-name="title" class="rf-card__title">Valley loop</h3>
<p>Nine kilometres along the river and back over the ridge, with a café at the halfway bridge.</p>
</div>
<footer data-name="footer" class="rf-card__footer">
<p>Walk · Moderate · 3 hours</p>
</footer>
</div>
</div>How Markdown is read
| You write | It becomes |
|---|---|
Content with no --- | The body |
One --- | Splits the content into the media zone (before) and the body (after) |
Two --- | Media, body and footer; leave the first zone empty for a footer without media |
| A paragraph directly followed by a heading, at the start of the body | The eyebrow above the title |
| The first heading in the body | The card's title, which also names a linked card for screen readers |
Add media and a footer
Put an image before the first ---, the body after it, and a short meta line after a second ---. Here Brunch classic becomes the eyebrow over the title.
{% card href="/runes/learning/recipe" media-position="start" %}

---
Brunch classic
### Tequila Sunrise
A bright, layered cocktail — five minutes, no shaker.
---
Cocktail · Easy
{% /card %}<div data-rune="card" data-rune-fields="{"media-position":"start"}">
<div data-section="media" data-name="media">
<img src="https://assets.refrakt.md/tequila-sunrise.png" alt="A tequila sunrise cocktail">
</div>
<p data-name="eyebrow">Brunch classic</p>
<div data-name="body">
<h3 id="tequila-sunrise" data-name="title">Tequila Sunrise</h3>
<p>A bright, layered cocktail — five minutes, no shaker.</p>
</div>
<footer data-name="footer">
<p>Cocktail · Easy</p>
</footer>
<a data-name="link" href="/runes/learning/recipe" data-link="stretch"></a>
</div><div class="rf-card" data-media-position="start" data-rune="card" data-density="full">
<div data-section="media" data-name="media" class="rf-card__media" data-guest-fit="clip" data-guest-posture="presentational">
<img src="https://assets.refrakt.md/tequila-sunrise.png" alt="A tequila sunrise cocktail" />
</div>
<div data-name="content" class="rf-card__content">
<p data-name="eyebrow" class="rf-card__eyebrow" data-section="eyebrow">Brunch classic</p>
<div data-name="body" class="rf-card__body" data-section="body">
<h3 id="tequila-sunrise" data-name="title" class="rf-card__title">Tequila Sunrise</h3>
<p>A bright, layered cocktail — five minutes, no shaker.</p>
</div>
<footer data-name="footer" class="rf-card__footer">
<p>Cocktail · Easy</p>
</footer>
</div>
<a data-name="link" href="/runes/learning/recipe" data-link="stretch" class="rf-card__link"></a>
</div>The media zone takes any block, not only an image: a codegroup, a chart, a map or a running sandbox fit the same way. Media guests shows each one in a card.
Place the media
The media always comes first in the source; media-position decides where it shows:
toporbottomstacks it above or below the body.startorendputs it beside the body on wide screens, and above it once the card is narrow.coverlays the body over the media (see Cover mode).
When the media sits beside the body, media-ratio sets its share of the width (1/3 to 2/3), valign aligns the two columns, and collapse picks the container width at which they stack (sm, md, lg, or never). Every rune with a media zone takes these same attributes.
Link the whole card
href makes the entire card one link. Links inside the body or footer stay clickable, and screen readers announce the link by the card's title.
{% card href="/guide/getting-started/" %}
### Getting started
Read the five-minute guide.
{% /card %}
Because a linked card is a single click target, an interactive media guest such as a codegroup or a live map shows its static form and passes clicks through to the link, and the build warns. Drop href if the guest needs to stay interactive. To make any other block a link, wrap it in link.
Lift the card and frame its media
elevation sets how far the card stands off the page, from sunken to overlay. The frame-* attributes shape the media zone: frame-aspect gives it a fixed shape and frame-anchor picks the focal point of the crop.
{% card elevation="raised" frame-aspect="16/9" frame-anchor="top left" %}

---
### Old-growth trail
A shaded two-hour walk among trees that predate the town.
{% /card %}<div data-rune="card" data-rune-fields="{"media-position":"top"}" elevation="raised">
<div data-section="media" data-name="media">
<img src="https://assets.refrakt.md/media-text-old-growth.jpg" alt="Moss-covered trunks in an old-growth forest">
</div>
<div data-name="body">
<h3 id="old-growth-trail" data-name="title">Old-growth trail</h3>
<p>A shaded two-hour walk among trees that predate the town.</p>
</div>
<meta data-field="frame-aspect" content="16/9">
<meta data-field="frame-anchor" content="top left">
</div>
Old-growth trail
A shaded two-hour walk among trees that predate the town.
<div class="rf-card" data-media-position="top" data-elevation="raised" data-rune="card" data-density="full">
<div data-section="media" data-name="media" class="rf-card__media" data-guest-fit="clip" style="--frame-aspect: 16/9; --frame-anchor: top left">
<img src="https://assets.refrakt.md/media-text-old-growth.jpg" alt="Moss-covered trunks in an old-growth forest" />
</div>
<div data-name="content" class="rf-card__content">
<div data-name="body" class="rf-card__body" data-section="body">
<h3 id="old-growth-trail" data-name="title" class="rf-card__title">Old-growth trail</h3>
<p>A shaded two-hour walk among trees that predate the town.</p>
</div>
</div>
</div>Surfaces lists every elevation step and frame facet, including displacement and silhouette shadows.
Cover mode
media-position="cover" turns the card into a poster: the media fills the card and the body sits over it.
{% card href="/runes/learning/recipe" media-position="cover" scrim-type="frost" scrim-blur="md" height="lg" %}

---
Brunch classic
### Tequila Sunrise
A bright, layered cocktail — five minutes, no shaker.
{% /card %}<div data-rune="card" data-rune-fields="{"media-position":"cover","height":"lg"}">
<div data-section="media" data-name="media">
<img src="https://assets.refrakt.md/tequila-sunrise.png" alt="A tequila sunrise cocktail">
</div>
<p data-name="eyebrow">Brunch classic</p>
<div data-name="body">
<h3 id="tequila-sunrise" data-name="title">Tequila Sunrise</h3>
<p>A bright, layered cocktail — five minutes, no shaker.</p>
</div>
<a data-name="link" href="/runes/learning/recipe" data-link="stretch"></a>
<meta data-field="scrim-type" content="frost">
<meta data-field="scrim-blur" content="md">
</div><div class="rf-card rf-card--cover" data-media-position="cover" data-height="lg" data-scrim-type="frost" data-scrim-blur="md" data-rune="card" data-density="full" data-cover-scope="full">
<div data-section="media" data-name="media" class="rf-card__media" data-guest-fit="clip" data-guest-posture="presentational">
<img src="https://assets.refrakt.md/tequila-sunrise.png" alt="A tequila sunrise cocktail" />
</div>
<div data-name="content" class="rf-card__content" data-color-scheme="dark">
<p data-name="eyebrow" class="rf-card__eyebrow" data-section="eyebrow">Brunch classic</p>
<div data-name="body" class="rf-card__body" data-section="body">
<h3 id="tequila-sunrise" data-name="title" class="rf-card__title">Tequila Sunrise</h3>
<p>A bright, layered cocktail — five minutes, no shaker.</p>
</div>
</div>
<a data-name="link" href="/runes/learning/recipe" data-link="stretch" class="rf-card__link"></a>
</div>- Shape. A cover card has no natural height, so give it
height(smtoxl) oraspect(such as3/4). Inside a bento cell or a collection row, the grid track sets the size instead. A card with only a background and no media needsheightoraspecttoo. - Where the text sits.
content-placetakes a block and an inline position, eachstart,centerorend:content-place="center center"centers the text. The default places it along the bottom of a portrait card and the start of a landscape one. It applies only in cover mode. - Legibility. A cover card darkens the media behind the text with a gradient scrim, and the text turns light to match.
scrimpicks the edge it darkens from,scrim-type="frost"blurs instead (as above, withscrim-blursetting how much), andscrim="none"turns it off.
Feed cards from a collection
In a collection body template, $item fills the card from each entity's fields:
{% collection type="page" filter="url:/blog/*" sort="date-desc" layout="grid" %}
{% card href=$item.url %}
### {% $item.data.title %}
{% date($item.data.date) %} — {% $item.data.description %}
{% /card %}
{% /collection %}
In a grid, cards in a row share the tallest card's height, so their footers line up. See collection → per-item templates for what $item holds.
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
href | string | — | Optional link target; makes the whole card clickable. |
content-place | string | — | Cover overlay anchor: "<block> <inline>" (e.g. "end start") or "auto" |
height | "sm" | "md" | "lg" | "xl" | — | Intrinsic card height (named scale) for cover / bg-only cards |
aspect | string | — | Intrinsic card aspect ratio (e.g. "16/9", "3/4") for cover / bg-only cards |
Inherited from the split layout preset
| Attribute | Type | Required | Description |
|---|---|---|---|
media-position | "top" | "bottom" | "start" | "end" | "cover" | — | Where the media zone sits relative to the content: above (top), below (bottom), or beside (start/end) |
media-ratio | "1/3" | "2/5" | "1/2" | "3/5" | "2/3" | — | Media zone’s share of the row width when media is beside content (start/end) |
valign | "top" | "center" | "bottom" | "stretch" | — | Cross-axis alignment when media is beside content (start/end); applies to the shorter zone |
collapse | "sm" | "md" | "lg" | "never" | — | Breakpoint at which side-by-side layouts collapse to a single stacked column |
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) |
dropcap
Per-instance drop-cap opt-in.
| Attribute | Type | Required | Description |
|---|---|---|---|
dropcap | boolean | — | Style the opening letter of a prose body as a drop cap. Honoured only when the body reads as prose; ignored otherwise. |
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) |
frame
Surface chrome: a named preset from the theme registry with inline `frame-*` overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
frame | string | — | Named frame preset presenting this block's media surface |
frame-anchor | string | — | Crop focal point when the guest is cut (object-position) |
frame-aspect | string | — | Aspect ratio of the framed media, e.g. "16/9" |
frame-displace | "top" | "bottom" | "end" | "bottom-end" | "top-end" | "both" | — | Edge/corner the framed guest moves toward |
frame-displace-mode | "peek" | "bleed" | — | How displacement renders: `peek` (default) translates the guest visually inside its frame target; `bleed` uses negative margin on the media zone so following layout pulls up — extends past a section like a hero without leaving a gap above |
frame-offset | "none" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | — | Displacement distance (non-linear named scale: sm…xl ride the block-spacing tokens, 2xl/3xl/4xl step up to section-spacing for bleed-mode displacements that clear a section edge) |
frame-overflow | "clip" | "bleed" | — | How the frame handles a guest whose content is wider than it: `clip` (default) keeps it inside the rounded frame; `bleed` runs an overflowing guest out to the layout edge on a narrow viewport so it reads as cropped by the screen (a bleed host only — hero/feature) |
frame-oversize | string | — | How far the guest exceeds its slot (scale factor) |
frame-place | string | — | Guest-box alignment in the slot (e.g. "left top") |
frame-shadow | "none" | "sm" | "md" | "lg" | — | Silhouette drop-shadow strength for the framed media |
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) |
reading
Editorial register for body text. You pick the register; the theme decides how it looks.
| Attribute | Type | Required | Description |
|---|---|---|---|
reading | "fine" | "ui" | "prose" | — | Reading register for this block’s body: fine | ui | prose. The theme sets how each one looks. |
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 |
|---|---|
| prominence | this rune has no page-section header or featured quotation |
See also
- collection — feeds cards from registry entities through a body template.
- Surfaces and Media guests — the shared vocabulary for frames, cover layouts and what the media zone can hold.
