# Breadcrumb

A trail of links that shows where the current page sits.

Where the current page sits: a trail of links from the top level to the page, separated by small carets that point the reading direction. Links are muted text that darkens on hover; the page itself is ink and not a link. Names wrap, never cut. A long trail can fold its middle into a ghost ⋯ button that opens a Menu of the hidden pages.

Kind: component · Category: Navigation · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add breadcrumb
```

It writes the folder `breadcrumb/` into the project's ui folder (`index.ts`, `breadcrumb.tsx`, `Breadcrumb.vue`, `Breadcrumb.svelte`, `breadcrumb.recipe.ts`), and what it is built from: [Button](/components/button.md), [Menu](/components/menu.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Breadcrumb } from "@/components/ui/breadcrumb";
```

```vue
import { Breadcrumb } from "@/components/ui/breadcrumb";
```

```svelte
import { Breadcrumb } from "$lib/components/ui/breadcrumb";
```

## Parts

In the DOM the root carries `data-slot="breadcrumb"` and each part `data-slot="breadcrumb-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `nav` | `breadcrumb` |  | A navigation landmark with an aria-label ("Breadcrumb"). |
| `list` | `ol` | `breadcrumb-list` |  | The ordered trail: a wrapping flex row (gap 6px across, 4px between lines), 13px text on a 20px line, ink-2. |
| `item` | `li` | `breadcrumb-item` | repeats | One step of the trail: its link, its page or the ellipsis. |
| `link` | `a` | `breadcrumb-link` | optional, repeats | A page above the current one: ink-2, ink on hover (fine pointer) and while pressed; colour over duration.fast. Wraps anywhere, never cut; keeps its own direction. A hit area 6px taller on each side (40px on coarse pointers) without changing its look. An item without an href is the same text, not a link. |
| `page` | `span` | `breadcrumb-page` | optional | The current page (the last item): ink, aria-current="page", not a link. |
| `separator` | `li` | `breadcrumb-separator` | repeats | role=presentation and aria-hidden: a 12px caret-right in ink-3 between two items, mirrored right-to-left. |
| `ellipsis` | `button` | `breadcrumb-ellipsis` | optional | The real Button (ghost, xs, square, muted, dots-three) as the trigger of a Menu that lists the folded pages; named by its Tooltip; marked data-breadcrumb="ellipsis". It sits on the 20px text line (negative block margins). |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `array` |  | The trail from the top level to the current page: { label, href? }. The last one is the current page. |
| `maxItems` | `number` |  | Show at most this many items (2 or more): the first, the ⋯ menu, then the last maxItems − 1. Omitted: every item. |
| `label` | `string` | `"Breadcrumb"` | The landmark's accessible name. |
| `ellipsisLabel` | `string` | `"Show hidden pages"` | The ⋯ button's name and tooltip. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `navigate` | (href: string \| undefined, item) when a link or a folded page is chosen. React onNavigate, Vue @navigate, Svelte onnavigate; given, it replaces the browser's own navigation (client routers); a click with a modifier key keeps the browser's. |

## States

`hover`, `press`, `focus-visible`, `current`

## Keyboard and accessibility

Role: navigation (an ordered list of links).

Keyboard:

- Tab reaches each link, then the ⋯ button; the current page is not a stop
- Enter follows a link; Enter, Space or ArrowDown on ⋯ open its menu (the Menu's keys)

Notes:

- The landmark is named "Breadcrumb" (label); the current page carries aria-current="page".
- Separators are hidden from assistive technology; the list's order says the hierarchy.
- The ⋯ button is named by its tooltip (ellipsisLabel); the menu lists the folded pages in order.

## Motion

- links: colour over duration.fast (hover gated to a fine pointer); the press darkens to ink
- the ⋯ button and its menu: the Button's and the Menu's own
- nothing else moves; nothing plays on first paint

## Tokens

`color.ink`, `color.ink-2`, `color.ink-3`, `radius.chip`, `text.sm`, `duration.fast`

## Dependencies

- [Button](/components/button.md)
- [Menu](/components/menu.md)
- [Tooltip](/components/tooltip.md)

## Examples

### A deploy inside a project

React · `deploy-page.tsx`

```tsx
import { Breadcrumb } from "@/components/ui/breadcrumb";

export default function DeployPage() {
  return (
    <Breadcrumb
      items={[
        { label: "Northwind", href: "/northwind" },
        { label: "web-app", href: "/northwind/web-app" },
        { label: "Deploys", href: "/northwind/web-app/deploys" },
        { label: "dpl_7f3a9c" },
      ]}
    />
  );
}
```

Vue · `deploy-page.vue`

```vue
<script setup lang="ts">
import { Breadcrumb } from "@/components/ui/breadcrumb";
</script>

<template>
  <Breadcrumb
    :items="[
      { label: 'Northwind', href: '/northwind' },
      { label: 'web-app', href: '/northwind/web-app' },
      { label: 'Deploys', href: '/northwind/web-app/deploys' },
      { label: 'dpl_7f3a9c' },
    ]"
  />
</template>
```

Svelte · `deploy-page.svelte`

```svelte
<script lang="ts">
  import { Breadcrumb } from "$lib/components/ui/breadcrumb";
</script>

<Breadcrumb
  items={[
    { label: "Northwind", href: "/northwind" },
    { label: "web-app", href: "/northwind/web-app" },
    { label: "Deploys", href: "/northwind/web-app/deploys" },
    { label: "dpl_7f3a9c" },
  ]}
/>
```

### A deep settings page, folded

React · `settings-folded.tsx`

```tsx
import { Breadcrumb } from "@/components/ui/breadcrumb";

/* a deep page keeps the first and the last two; the ⋯ menu holds the rest */
export default function SettingsFolded() {
  return (
    <Breadcrumb
      maxItems={3}
      items={[
        { label: "Northwind", href: "/northwind" },
        { label: "billing-api", href: "/northwind/billing-api" },
        { label: "Settings", href: "/northwind/billing-api/settings" },
        { label: "Environment variables", href: "/northwind/billing-api/settings/env" },
        { label: "Production", href: "/northwind/billing-api/settings/env/production" },
        { label: "STRIPE_WEBHOOK_SECRET" },
      ]}
    />
  );
}
```

Vue · `settings-folded.vue`

```vue
<script setup lang="ts">
import { Breadcrumb } from "@/components/ui/breadcrumb";
</script>

<!-- a deep page keeps the first and the last two; the ⋯ menu holds the rest -->
<template>
  <Breadcrumb
    :maxItems="3"
    :items="[
      { label: 'Northwind', href: '/northwind' },
      { label: 'billing-api', href: '/northwind/billing-api' },
      { label: 'Settings', href: '/northwind/billing-api/settings' },
      { label: 'Environment variables', href: '/northwind/billing-api/settings/env' },
      { label: 'Production', href: '/northwind/billing-api/settings/env/production' },
      { label: 'STRIPE_WEBHOOK_SECRET' },
    ]"
  />
</template>
```

Svelte · `settings-folded.svelte`

```svelte
<script lang="ts">
  import { Breadcrumb } from "$lib/components/ui/breadcrumb";
</script>

<!-- a deep page keeps the first and the last two; the ⋯ menu holds the rest -->
<Breadcrumb
  maxItems={3}
  items={[
    { label: "Northwind", href: "/northwind" },
    { label: "billing-api", href: "/northwind/billing-api" },
    { label: "Settings", href: "/northwind/billing-api/settings" },
    { label: "Environment variables", href: "/northwind/billing-api/settings/env" },
    { label: "Production", href: "/northwind/billing-api/settings/env/production" },
    { label: "STRIPE_WEBHOOK_SECRET" },
  ]}
/>
```

### With a client router

React · `client-router.tsx`

```tsx
import { useState } from "react";
import { Breadcrumb } from "@/components/ui/breadcrumb";
import { Button } from "@/components/ui/button";

const pages = [
  { label: "Northwind", href: "/northwind" },
  { label: "mobile", href: "/northwind/mobile" },
  { label: "Deploys", href: "/northwind/mobile/deploys" },
  { label: "dpl_2c81e4", href: "/northwind/mobile/deploys/dpl_2c81e4" },
];

/* onNavigate takes over plain clicks (Cmd/Ctrl-click still opens a tab): hand them to your router */
export default function ClientRouter() {
  const [depth, setDepth] = useState(pages.length);
  const trail = pages.slice(0, depth);
  const child = pages[depth];
  return (
    <div className="flex w-80 flex-col items-start gap-3">
      <Breadcrumb
        items={trail.map((page, i) => (i === depth - 1 ? { label: page.label } : page))}
        onNavigate={(href) => setDepth(pages.findIndex((page) => page.href === href) + 1)}
      />
      {child && <Button size="sm" onClick={() => setDepth(depth + 1)}>Open {child.label}</Button>}
    </div>
  );
}
```

Vue · `client-router.vue`

```vue
<script setup lang="ts">
import { computed, ref } from "vue";
import { Breadcrumb } from "@/components/ui/breadcrumb";
import { Button } from "@/components/ui/button";

const pages = [
  { label: "Northwind", href: "/northwind" },
  { label: "mobile", href: "/northwind/mobile" },
  { label: "Deploys", href: "/northwind/mobile/deploys" },
  { label: "dpl_2c81e4", href: "/northwind/mobile/deploys/dpl_2c81e4" },
];

/* @navigate takes over plain clicks (Cmd/Ctrl-click still opens a tab): hand them to your router */
const depth = ref(pages.length);
const trail = computed(() => pages.slice(0, depth.value).map((page, i) => (i === depth.value - 1 ? { label: page.label } : page)));
const child = computed(() => pages[depth.value]);
</script>

<template>
  <div class="flex w-80 flex-col items-start gap-3">
    <Breadcrumb
      :items="trail"
      @navigate="(href) => (depth = pages.findIndex((page) => page.href === href) + 1)"
    />
    <Button v-if="child" size="sm" @click="depth = depth + 1">Open {{ child.label }}</Button>
  </div>
</template>
```

Svelte · `client-router.svelte`

```svelte
<script lang="ts">
  import { Breadcrumb } from "$lib/components/ui/breadcrumb";
  import { Button } from "$lib/components/ui/button";

  const pages = [
    { label: "Northwind", href: "/northwind" },
    { label: "mobile", href: "/northwind/mobile" },
    { label: "Deploys", href: "/northwind/mobile/deploys" },
    { label: "dpl_2c81e4", href: "/northwind/mobile/deploys/dpl_2c81e4" },
  ];

  /* onnavigate takes over plain clicks (Cmd/Ctrl-click still opens a tab): hand them to your router */
  let depth = $state(pages.length);
  const trail = $derived(pages.slice(0, depth).map((page, i) => (i === depth - 1 ? { label: page.label } : page)));
  const child = $derived(pages[depth]);
</script>

<div class="flex w-80 flex-col items-start gap-3">
  <Breadcrumb
    items={trail}
    onnavigate={(href) => (depth = pages.findIndex((page) => page.href === href) + 1)}
  />
  {#if child}
    <Button size="sm" onclick={() => (depth = depth + 1)}>Open {child.label}</Button>
  {/if}
</div>
```

## Recipe

`breadcrumb.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* breadcrumb — the trail to the current page. The models: the pager for the ghost muted square
 * Button and the caret that mirrors right-to-left, the text row for text that wraps whole and keeps
 * its own direction. 13px text on a 20px line; ancestors ink-2 → ink on hover and while pressed
 * (the inline-choice hover, colour only: text links do not scale); the current page ink; the
 * separators ink-3.
 *
 * Names are never cut: a long one wraps anywhere, and the trail wraps between items. A link keeps
 * its look but gets a hit area 6px taller above and below (not wider, so it never pokes out of a narrow row) (40px tall on coarse pointers) from an
 * ::after; its focus ring follows radius.chip. The ⋯ (the real Button, ghost xs square muted,
 * marked data-breadcrumb="ellipsis") is 24px, pulled onto the 20px line by negative block margins
 * so a folded trail is as tall as an unfolded one. Parts are found by data-slot; the root slot is
 * `base`. */

export const breadcrumb = tv({
  slots: {
    base: "min-w-0",
    list: "m-0 flex min-w-0 list-none flex-wrap items-center gap-x-1.5 gap-y-1 p-0 text-sm leading-5 text-ink-2",
    item: "inline-flex min-w-0 items-center",
    link: [
      "relative min-w-0 rounded-chip text-ink-2 no-underline wrap-anywhere [unicode-bidi:plaintext]",
      "motion-colors-fast [&[href]]:hover:text-ink [&[href]]:active:text-ink",
      "[&[href]]:after:absolute [&[href]]:after:inset-x-0 [&[href]]:after:-inset-y-1.5 [&[href]]:after:content-['']",
      "pointer-coarse:[&[href]]:after:-inset-y-2.5",
    ],
    page: "min-w-0 text-ink wrap-anywhere [unicode-bidi:plaintext]",
    separator: "inline-flex shrink-0 items-center text-[12px] text-ink-3 [&:dir(rtl)>[data-slot=icon]]:[transform:scaleX(-1)]",
    /* passed to the ⋯ Button as className, after its own classes */
    ellipsis: "-my-0.5",
  },
});

export type BreadcrumbRecipeProps = VariantProps<typeof breadcrumb>;
```
