Breadcrumb

Where the page sits in the app.

A labelled navigation landmark holding an ordered trail. The last step is the page you’re on, marked with aria-current.

A trail too long for its space wraps onto more lines. Set overflow="scroll" on the list to keep it to one line instead, as in a header: it starts scrolled to the page you’re on, scrolls sideways to the rest, and fades out at an end with more past it.

Preview
basic.tsx
import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
  BreadcrumbSeparator,
} from "~/components/ui/breadcrumb"

export default function Example() {
  return (
    <Breadcrumb>
      <BreadcrumbList>
        <BreadcrumbItem>
          <BreadcrumbLink href="#publications">Publications</BreadcrumbLink>
        </BreadcrumbItem>
        <BreadcrumbSeparator />
        <BreadcrumbItem>
          <BreadcrumbLink href="#daily-brew">The Daily Brew</BreadcrumbLink>
        </BreadcrumbItem>
        <BreadcrumbSeparator />
        <BreadcrumbItem>
          <BreadcrumbLink href="#editions">Editions</BreadcrumbLink>
        </BreadcrumbItem>
        <BreadcrumbSeparator />
        <BreadcrumbItem>
          <BreadcrumbPage>Weekend Edition</BreadcrumbPage>
        </BreadcrumbItem>
      </BreadcrumbList>
    </Breadcrumb>
  )
}

Dependencies

What it's built from and what's built from it in Base, read from the imports in its source.

UsesTextprimitive
Used byNothing yet.
Packages lucide-react@1.73.0

Installation

Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.

With the CLI

terminal
npx shadcn@latest add https://design.zepez.dev/r/base/breadcrumb.json

Manually

Install its packages:

terminal
npm install lucide-react@1.73.0

Add the components it uses first, listed under Dependencies.

Then copy the source:

components/ui/breadcrumb.tsx
import { ChevronRight } from "lucide-react"
import * as React from "react"

import { textVariants } from "~/components/ui/text"
import { cn } from "~/lib/utils"

/** Where the page sits in the app: a labelled navigation landmark holding a `BreadcrumbList`. */
function Breadcrumb({ "aria-label": label = "Breadcrumb", ...props }: React.ComponentProps<"nav">) {
  return <nav data-slot="breadcrumb" aria-label={label} {...props} />
}

type BreadcrumbListProps = React.ComponentProps<"ol"> & {
  /**
   * What a trail too long for its space does. `wrap` breaks onto more lines. `scroll` keeps one
   * line that scrolls sideways, starting at the page you're on, and fades where there's more.
   */
  overflow?: "wrap" | "scroll"
}

/** The trail, in order. */
function BreadcrumbList({ overflow = "wrap", className, ...props }: BreadcrumbListProps) {
  const ref = React.useRef<HTMLOListElement>(null)
  const [more, setMore] = React.useState({ before: false, after: false })
  React.useLayoutEffect(() => {
    const list = ref.current
    if (overflow !== "scroll" || list === null) return undefined
    const measure = () =>
      setMore({
        before: list.scrollLeft > 1,
        after: list.scrollLeft + list.clientWidth < list.scrollWidth - 1,
      })
    // Start at the end, the page you're on, and stay there as the steps change size (fonts
    // load, the space changes) until you scroll the trail yourself.
    let pinned = true
    const pin = () => {
      if (pinned) list.scrollLeft = list.scrollWidth
      measure()
    }
    const unpin = () => {
      pinned = false
    }
    pin()
    list.addEventListener("scroll", measure, { passive: true })
    list.addEventListener("pointerdown", unpin)
    list.addEventListener("wheel", unpin, { passive: true })
    list.addEventListener("focusin", unpin)
    const resized = new ResizeObserver(pin)
    resized.observe(list)
    for (const step of list.children) resized.observe(step)
    return () => {
      list.removeEventListener("scroll", measure)
      list.removeEventListener("pointerdown", unpin)
      list.removeEventListener("wheel", unpin)
      list.removeEventListener("focusin", unpin)
      resized.disconnect()
    }
  }, [overflow])
  return (
    <ol
      ref={ref}
      data-slot="breadcrumb-list"
      data-overflow={overflow}
      data-more-before={more.before || undefined}
      data-more-after={more.after || undefined}
      className={cn(
        textVariants({ size: "sm", tone: "muted" }),
        "flex flex-wrap items-center gap-xs wrap-break-word sm:gap-md",
        "data-[overflow=scroll]:[scrollbar-width:none] data-[overflow=scroll]:flex-nowrap data-[overflow=scroll]:overflow-x-auto data-[overflow=scroll]:whitespace-nowrap",
        // Fades out at an end with more past it.
        "data-more-after:mask-r-from-85% data-more-before:mask-l-from-85%",
        className,
      )}
      {...props}
    />
  )
}

/** One step: a `BreadcrumbLink`, or the `BreadcrumbPage` you're on. */
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
  return (
    <li
      data-slot="breadcrumb-item"
      className={cn("inline-flex items-center gap-xs", className)}
      {...props}
    />
  )
}

/** A step you can go back to. */
function BreadcrumbLink({ className, children, ...props }: React.ComponentProps<"a">) {
  return (
    <a
      data-slot="breadcrumb-link"
      className={cn(
        "transition-colors outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/30",
        className,
      )}
      {...props}
    >
      {children}
    </a>
  )
}

/** The page you're on. */
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
  return (
    <span
      data-slot="breadcrumb-page"
      aria-current="page"
      className={cn(textVariants({ weight: "normal" }), "text-foreground", className)}
      {...props}
    />
  )
}

/** The mark between steps, a chevron unless you pass your own. */
function BreadcrumbSeparator({ children, className, ...props }: React.ComponentProps<"li">) {
  return (
    <li
      data-slot="breadcrumb-separator"
      role="presentation"
      aria-hidden="true"
      className={cn("[&>svg]:size-3.5", className)}
      {...props}
    >
      {children ?? <ChevronRight />}
    </li>
  )
}

export type { BreadcrumbListProps }
export {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
  BreadcrumbSeparator,
}

API reference

Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.

Breadcrumb

Where the page sits in the app: a labelled navigation landmark holding a BreadcrumbList.

Takes the props of a native div.

BreadcrumbItem

One step: a BreadcrumbLink, or the BreadcrumbPage you're on.

Takes the props of a native div.

A step you can go back to.

Takes the props of a native div.

BreadcrumbList

The trail, in order.

overflowours

What a trail too long for its space does. wrap breaks onto more lines. scroll keeps one line that scrolls sideways, starting at the page you're on, and fades where there's more.

Type "wrap" | "scroll" · Default wrap

BreadcrumbPage

The page you're on.

Takes the props of a native div.

BreadcrumbSeparator

The mark between steps, a chevron unless you pass your own.

Takes the props of a native div.