Site›Breadcrumb

core

Breadcrumb

Navigation breadcrumbs showing page hierarchy

Source

import Markdoc from '@markdoc/markdoc';
const { Tag } = Markdoc;
import { createContentModelSchema, createComponentRenderable, renderNodes } from '../lib/index.js';

export const BREADCRUMB_AUTO_SENTINEL = '__breadcrumb-auto';

export const breadcrumbSchema = {
	type: 'BreadcrumbList',
	lists: ['itemListElement'],
	children: {
		'breadcrumb-item': {
			type: 'ListItem',
			property: 'itemListElement',
			properties: { name: 'name', url: 'item' },
			generated: { position: 'index' },
		},
	},
} as const;

export const breadcrumb = createContentModelSchema({
	schema: breadcrumbSchema,
	attributes: {
		separator: {
			type: String,
			required: false,
			default: '/',
			description: 'Character between breadcrumb items',
		},
		auto: {
			type: Boolean,
			required: false,
			default: false,
			description: 'Automatically generate from page hierarchy',
		},
	},
	contentModel: (attrs) => {
		if (attrs.auto) {
			return { type: 'sequence' as const, fields: [] };
		}
		return {
			type: 'sequence' as const,
			fields: [{ name: 'list', match: 'list' as const, optional: true, greedy: true }],
		};
	},
	transform(resolved, attrs, config) {
		const separatorMeta = new Tag('meta', { content: attrs.separator });

		if (attrs.auto) {
			const sentinelMeta = new Tag('meta', {
				'data-field': BREADCRUMB_AUTO_SENTINEL,
				content: 'true',
			});
			const emptyList = new Tag('ol', {}, []);

			return createComponentRenderable({
				rune: 'breadcrumb',
				tag: 'nav',
				properties: {
					separator: separatorMeta,
				},
				refs: {
					items: emptyList,
				},
				children: [sentinelMeta, emptyList],
			});
		}

		const children = renderNodes(resolved.list, config);

		const listItems: any[] = [];
		for (const node of children.toArray()) {
			if (Tag.isTag(node) && (node.name === 'ul' || node.name === 'ol')) {
				for (const li of (node as any).children) {
					if (Tag.isTag(li) && li.name === 'li') {
						const link = (li as any).children.find((c: any) => Tag.isTag(c) && c.name === 'a');

						if (link) {
							const nameSpan = new Tag('span', { hidden: true }, link.children);
							const urlLink = new Tag('a', { href: link.attributes.href }, link.children);

							listItems.push(
								createComponentRenderable({
									rune: 'breadcrumb-item',
									tag: 'li',
									properties: {
										name: nameSpan,
										url: urlLink,
									},
									children: [nameSpan, urlLink],
								}) as any,
							);
						} else {
							const text = li.children
								.filter((c: any) => typeof c === 'string')
								.join('')
								.trim();
							const nameSpan = new Tag('span', {}, text ? [text] : li.children);

							listItems.push(
								createComponentRenderable({
									rune: 'breadcrumb-item',
									tag: 'li',
									properties: {
										name: nameSpan,
									},
									children: [nameSpan],
								}) as any,
							);
						}
					}
				}
			}
		}

		const itemsList = new Tag('ol', {}, listItems);

		return createComponentRenderable({
			rune: 'breadcrumb',
			tag: 'nav',
			properties: {
				separator: separatorMeta,
			},
			refs: {
				items: itemsList,
			},
			children: [itemsList],
		});
	},
});

View packages/runes/src/tags/breadcrumb.ts on GitHub

Navigation breadcrumbs from a list of links. Each linked item is a navigable breadcrumb, and the last item (without a link) represents the current page.

Basic usage

A breadcrumb trail using the default / separator.

{% breadcrumb %}
- [Home](/)
- [Getting started](/docs/getting-started)
- [Tabs](/runes/tabs)
- Breadcrumb
{% /breadcrumb %}
<nav data-rune="breadcrumb" data-rune-fields="{&quot;separator&quot;:&quot;/&quot;}" typeof="BreadcrumbList" data-schema-lists="[&quot;itemListElement&quot;]">
  <ol data-name="items">
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span hidden data-field="name" property="name">Home</span>
      <a href="/" data-field="url" property="item">Home</a>
      <meta property="position" content="1">
    </li>
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span hidden data-field="name" property="name">Getting started</span>
      <a href="/docs/getting-started" data-field="url" property="item">Getting started</a>
      <meta property="position" content="2">
    </li>
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span hidden data-field="name" property="name">Tabs</span>
      <a href="/runes/tabs" data-field="url" property="item">Tabs</a>
      <meta property="position" content="3">
    </li>
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span data-field="name" property="name">Breadcrumb</span>
      <meta property="position" content="4">
    </li>
  </ol>
</nav>
<nav class="rf-breadcrumb" typeof="BreadcrumbList" data-schema-lists="[&quot;itemListElement&quot;]" data-separator="/" data-elevation="flush" data-rune="breadcrumb" data-density="minimal" style="--separator: &quot;/&quot;">
  <ol data-name="items" class="rf-breadcrumb__items">
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span hidden data-field="name" property="name">Home</span>
      <a href="/" data-field="url" property="item">Home</a>
      <meta property="position" content="1" />
    </li>
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span hidden data-field="name" property="name">Getting started</span>
      <a href="/docs/getting-started" data-field="url" property="item">Getting started</a>
      <meta property="position" content="2" />
    </li>
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span hidden data-field="name" property="name">Tabs</span>
      <a href="/runes/tabs" data-field="url" property="item">Tabs</a>
      <meta property="position" content="3" />
    </li>
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span data-field="name" property="name">Breadcrumb</span>
      <meta property="position" content="4" />
    </li>
  </ol>
</nav>

How Markdown is read

You writeIt becomes
A listThe trail, one crumb per item, in order
An item that is a linkA crumb that links to that page
An item without a linkA plain-text crumb, normally the current page

Custom separator

Use the separator attribute to change the divider between items.

{% breadcrumb separator="›" %}
- [Home](/)
- [Getting started](/docs/getting-started)
- Current page
{% /breadcrumb %}
<nav data-rune="breadcrumb" data-rune-fields="{&quot;separator&quot;:&quot;›&quot;}" typeof="BreadcrumbList" data-schema-lists="[&quot;itemListElement&quot;]">
  <ol data-name="items">
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span hidden data-field="name" property="name">Home</span>
      <a href="/" data-field="url" property="item">Home</a>
      <meta property="position" content="1">
    </li>
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span hidden data-field="name" property="name">Getting started</span>
      <a href="/docs/getting-started" data-field="url" property="item">Getting started</a>
      <meta property="position" content="2">
    </li>
    <li data-rune="breadcrumb-item" typeof="ListItem" property="itemListElement">
      <span data-field="name" property="name">Current page</span>
      <meta property="position" content="3">
    </li>
  </ol>
</nav>
<nav class="rf-breadcrumb" typeof="BreadcrumbList" data-schema-lists="[&quot;itemListElement&quot;]" data-separator="›" data-elevation="flush" data-rune="breadcrumb" data-density="minimal" style="--separator: &quot;›&quot;">
  <ol data-name="items" class="rf-breadcrumb__items">
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span hidden data-field="name" property="name">Home</span>
      <a href="/" data-field="url" property="item">Home</a>
      <meta property="position" content="1" />
    </li>
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span hidden data-field="name" property="name">Getting started</span>
      <a href="/docs/getting-started" data-field="url" property="item">Getting started</a>
      <meta property="position" content="2" />
    </li>
    <li class="rf-breadcrumb-item" typeof="ListItem" property="itemListElement" data-rune="breadcrumb-item" data-density="full">
      <span data-field="name" property="name">Current page</span>
      <meta property="position" content="3" />
    </li>
  </ol>
</nav>

Attributes

AttributeTypeRequiredDescription
separatorstring—Character between breadcrumb items
autoboolean—Automatically generate from page hierarchy

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.

AttributeTypeRequiredDescription
bgstring—Background preset applied to this block
bg-fromstring—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-tostring—Gradient end colour — a semantic token name
bg-viastring—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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
reveal"none" | "fade" | "slide" | "scale" | "blur"—Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography
staggerboolean—Cascade this block's items in as it reveals (no-op on single-child runes)
spacing

Block-level rhythm override.

AttributeTypeRequiredDescription
spacing"flush" | "tight" | "default" | "loose" | "breathe"—Vertical spacing above and below this block
substrate

Generated pattern fills behind the content, drawn by the theme.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
tintstring—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.

AttributeTypeRequiredDescription
width"compact" | "narrow" | "content" | "wide" | "full"—Maximum width constraint for this block
Not availableWhy
dropcap, readingthis rune declares no prose body
framethis rune declares neither a `frameTarget` nor a media section
prominencethis rune has no page-section header or featured quotation