Skip to the content
human-kit design
37 — Navigation

Breadcrumbs

The trail of pages above the current one, its middle folded when it runs long.

Installation

pnpm dlx @human-kit/design add breadcrumbs
npx @human-kit/design add breadcrumbs
yarn dlx @human-kit/design add breadcrumbs
bunx @human-kit/design add breadcrumbs

The command copies the files to src/lib/components/ui/breadcrumbs. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Breadcrumbs from '$lib/components/ui/breadcrumbs';
</script>

<Breadcrumbs.Root>
	<Breadcrumbs.List>
		<Breadcrumbs.Item>
			<Breadcrumbs.Link href="/patients">Patients</Breadcrumbs.Link>
			<Breadcrumbs.Separator />
		</Breadcrumbs.Item>
		<Breadcrumbs.Item>
			<Breadcrumbs.Link current>Ana María Ruiz</Breadcrumbs.Link>
		</Breadcrumbs.Item>
	</Breadcrumbs.List>
</Breadcrumbs.Root>

Examples

Folded trail

Past maxItems, the middle of the trail folds into a "…" button: the first page and the last maxItems - 1 stay. Put a Breadcrumbs.Ellipsis after the first item; a press unfolds the trail.

Guidelines

  • Use breadcrumbs on a page two levels or more down a hierarchy, above its title, to show where it sits and to go back up.
  • End the trail with the page the user is on, marked current and without an href.
  • Put a Breadcrumbs.Separator after the link of every item but the last.
  • Set maxItems when a trail can grow long, so it stays on one line. Fold it to three or four.
  • Breadcrumbs show where a page is, not the steps that led to it. For a flow in steps, use a stepper.

Accessibility

  • The root is a <nav> landmark named "Breadcrumb". Give an aria-label of your own when the page has two trails.
  • The list is an <ol>, so a screen reader says how many pages it holds and where each one is.
  • The current link carries aria-current="page". Without an href, or with disabled, a link is plain text and leaves the tab order.
  • The separators are hidden from screen readers: the list already parts the pages.
  • The "…" is a button named "Show N more pages". After it is pressed, the focus lands on the first page that comes into view.

API reference

Breadcrumbs.Root

PropTypeDefault
maxItemsnumber

How many items the trail shows before its middle folds. Without it, the trail never folds.

—
expandedboolean

Whether the user unfolded the trail. Bindable, to fold it again.

false
onExpandedChange(expanded: boolean) => void

Called when the trail unfolds or folds.

—
aria-labelstring

The name of the landmark, in the locale of the page.

'Breadcrumb'
elementHTMLElement | null

The rendered <nav>. Bindable.

—

Plus every attribute of a <nav>. It draws nothing of its own.

Breadcrumbs.List

PropTypeDefault
elementHTMLOListElement | null

The rendered <ol>. Bindable.

—

Plus every attribute of an <ol>.

Breadcrumbs.Item

PropTypeDefault
elementHTMLLIElement | null

The rendered <li>. Bindable.

—

Plus every attribute of an <li>. It holds a link and, after it, a separator.

PropTypeDefault
hrefstring

The address of the page. Without it, the link is plain text.

—
currentboolean

Marks the page the user is on: full ink, and aria-current="page".

false
disabledboolean

Keeps the text and drops the href and the tab stop.

false
elementHTMLAnchorElement | HTMLSpanElement | null

The rendered <a>, or <span> without an href. Bindable.

—

Plus every attribute of an <a>.

Breadcrumbs.Separator

PropTypeDefault
childrenSnippet

Your own sign in place of the chevron. The chevron turns round on a right-to-left page.

—

Plus every attribute of a <span>.

Breadcrumbs.Ellipsis

PropTypeDefault
childrenSnippet

Your own content in place of the three dots.

—
separatorSnippet

The sign after the button. Without it, a Breadcrumbs.Separator.

—
aria-labelstring

The name of the button.

'Show N more pages'
elementHTMLButtonElement | null

The rendered button, while the trail is folded. Bindable.

—

Plus every attribute of a <button>. It shows only while the trail is folded.