sveltelean Primitives
Version v0.18.0
The trail of this page
Code
<script lang="ts">
	import '@svelte-lean/styles/breadcrumb.css';
</script>

<nav aria-label="Breadcrumb" data-slean="breadcrumb">
	<ol>
		<li><a href="/">Home</a></li>
		<li><a href="/primitives">Primitives</a></li>
		<li><a href="/primitives/breadcrumb" aria-current="page">Breadcrumb</a></li>
	</ol>
</nav>
The separators are drawn in CSS and never announced; turn on RTL to see them mirror.

Examples

Collapsed levels

Middle levels in a popover
Code
<script lang="ts">
	import '@svelte-lean/styles/breadcrumb.css';
	import '@svelte-lean/styles/button.css';
	import '@svelte-lean/styles/popover.css';
</script>

<nav aria-label="Architecture breadcrumb" data-slean="breadcrumb">
	<ol>
		<li><a href="/">Home</a></li>
		<li>
			<button type="button" data-slean="button" data-variant="text" data-color="neutral" data-size="small" popovertarget="trail-more" aria-label="Show 2 more levels">
				…
			</button>
			<div id="trail-more" popover data-slean="popover" data-slean-align="start">
				<ul class="levels">
					<li><a href="/docs">Docs</a></li>
					<li><a href="/docs/architecture/native-first">Architecture</a></li>
				</ul>
			</div>
		</li>
		<li><a href="/docs/architecture/runtime-tiers" aria-current="page">Runtime tiers</a></li>
	</ol>
</nav>

<style>
	.levels {
		display: grid;
		gap: 0.25rem;
		margin: 0;
		padding: 0;
		list-style: none;
	}
</style>
A long trail keeps its ends; the middle levels open from a button.

Home icon

An icon link named by aria-label
Code
<script lang="ts">
	import '@svelte-lean/styles/breadcrumb.css';
</script>

<nav aria-label="Docs breadcrumb" data-slean="breadcrumb">
	<ol>
		<li>
			<a href="/" aria-label="Home">
				<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round">
					<path d="M3 10.5 12 3l9 7.5V21h-6v-6H9v6H3z" />
				</svg>
			</a>
		</li>
		<li><a href="/docs">Docs</a></li>
		<li><a href="/docs/installation" aria-current="page">Installation</a></li>
	</ol>
</nav>
The SVG is hidden; the link keeps its name.

Current page as text

A span with aria-current
Code
<script lang="ts">
	import '@svelte-lean/styles/breadcrumb.css';
</script>

<nav aria-label="Table breadcrumb" data-slean="breadcrumb">
	<ol>
		<li><a href="/">Home</a></li>
		<li><a href="/table">Table</a></li>
		<li><span aria-current="page">Pagination</span></li>
	</ol>
</nav>
When the current page should not be a link, a span is styled the same way.

Trail from the route

Levels from page.url in SvelteKit
Code
<script lang="ts">
	import '@svelte-lean/styles/breadcrumb.css';
	import { page } from '$app/state';

	// One level per path segment, the last one current.
	const trail = $derived.by(() => {
		const segments = page.url.pathname.split('/').filter(Boolean);
		return [
			{ href: '/', label: 'Home' },
			...segments.map((segment, i) => ({
				href: '/' + segments.slice(0, i + 1).join('/'),
				label: segment.charAt(0).toUpperCase() + segment.slice(1).replaceAll('-', ' ')
			}))
		];
	});
</script>

<nav aria-label="Page breadcrumb" data-slean="breadcrumb">
	<ol>
		{#each trail as level, i (level.href)}
			<li>
				<a href={level.href} aria-current={i === trail.length - 1 ? 'page' : undefined}>
					{level.label}
				</a>
			</li>
		{/each}
	</ol>
</nav>
One level per path segment; this is the trail of the page you are reading.

Usage

Plain markup with a stylesheet: install @svelte-lean/styles. No JavaScript runs.

stylesheets
import '@svelte-lean/styles/breadcrumb.css';

Name the landmark with aria-label="Breadcrumb" (or aria-labelledby), list the levels in an <ol> directly inside it, and mark the last item with aria-current="page". A page with several breadcrumbs gives each its own name.

Do not type separators into the markup; the stylesheet draws them.

Anatomy

PartElementdata-slean-partRequiredNotes
root<nav aria-label="Breadcrumb" data-slean="breadcrumb">–yesA named navigation landmark.
list<ol> directly in the root–yesOne <li> per level, from the site root to the current page.
current page<a href aria-current="page"> or <span aria-current="page">–yesThe last item.

Keyboard

KeyWhenResult
Tab/Shift+TabanywhereMoves between the links (native)
Enterfocus on a linkFollows it (native)

Styling

breadcrumb.css lays the items out in a wrapping row, draws each separator as a chevron on li + li::before (mirrored under :dir(rtl)), mutes the ancestors and sets the current page in the text color. Links get the shared focus ring and, on a coarse pointer, the small control height. The rules use child combinators, so a list nested in an item keeps its own styles. The tokens it reads:

TokenDefault (light)Applies to
--slean-fg-mutedvar(--slean-neutral-11)color
--slean-text-sm0.875remfont-size
--slean-leading1.5line-height
--slean-space-1calc(var(--slean-spacing) * 1)gap
--slean-space-2calc(var(--slean-spacing) * 2)gap
--slean-icon-chevron-righturl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6 4l4 4-4 4' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E")mask
--slean-radius-smcalc(var(--slean-radius) * 0.6)border-radius
--slean-fgvar(--slean-neutral-12)color
--slean-font-weight-medium500font-weight
--slean-focus-ringvar(--slean-focus-ring-width) solid var(--slean-focus-ring-color)outline
--slean-focus-ring-offset2pxoutline-offset
--slean-control-height-sm2remmin-block-size

State selectors the stylesheet targets, all from the platform or ARIA: :dir(rtl), :focus-visible, :hover, [aria-current="page"], [href].

Under the hood

Runtime and size
Tier
0 · Native
Behavior JS
0 B brotli · 0 B gzip · fixtures/results.json (native-only) · method
Platform features
<nav>, <ol>, aria-current="page", :dir(rtl)
Shared listeners
none
Per-instance listeners
none
Lazy state
none
Native base
<nav> + <ol> + aria-current="page"

Tier 0: no behavior module. The Vite plugin maps breadcrumb to no module, and the page ships no Svelte Lean JavaScript for it.

Why this implementation

A breadcrumb is links in a list inside a navigation landmark, which the WAI-ARIA Authoring Practices spell out: a named <nav>, an <ol>, and aria-current="page" on the last item. Nothing in it needs a script.

The one part that goes wrong in markup is the separator: a typed “/” or “>” is read aloud between every level. breadcrumb.css draws the separators as generated boxes with no text, mirrored under RTL, so the markup holds only the links.

The browser owns

  • the navigation landmark and its name
  • the list and the number of levels
  • the links, their focus and Enter
  • the current page state (aria-current)

Svelte Lean owns

  • breadcrumb.css: the row, the separators drawn with borders and mirrored under RTL
  • the current page’s weight, the link hover and focus ring, the coarse-pointer height
  • the contract
  • documentation
Accessibility
  • A named <nav> landmark, told apart from the page’s other navigation by its name.
  • An <ol>: screen readers announce the number of levels.
  • aria-current="page" on the current page, a link or a span.
  • The separators are empty generated boxes: not in the text, not announced.
Platform features
FeatureBaselineOutside the target
<nav>, <ol>, aria-currentWidely availableNot applicable
rotateBaseline 2022A separator is an unturned corner
:dir()Baseline 2023The chevrons point to the right under RTL as well
Without JavaScript

Fully functional: the levels are plain links.

Server rendering and hydration

Static markup, rendered with the page from its route.

Nothing is attached; the links work before and after hydration alike.

Compatibility

The elements and aria-current are widely available. The chevrons use the rotate property (Baseline 2022) and :dir() (Baseline 2023); without the first a separator is an unturned corner, without the second the chevrons point right under RTL as well.

Tests and source