Skip to content

Breadcrumb

Shows the path from the top of the app to the current page as a row of links.

Installation

pnpm dlx shadcn@latest add @silkware/breadcrumb

To copy the component by hand, install its dependencies:

pnpm add react-aria-components cn lucide-react

Then copy the source into components/ui/breadcrumb.tsx:

components/ui/breadcrumb.tsx
"use client"
import * as React from "react"import { cn } from "cn"import {  Breadcrumb as BreadcrumbPrimitive,  Breadcrumbs as BreadcrumbsPrimitive,  composeRenderProps,  Link as LinkPrimitive,  type BreadcrumbProps,  type BreadcrumbsProps,  type LinkProps,} from "react-aria-components"import { ChevronRightIcon, MoreHorizontalIcon } from "lucide-react"
function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) {  return (    <nav      aria-label="breadcrumb"      data-slot="breadcrumb"      className={cn(className)}      {...props}    />  )}
function BreadcrumbList<T extends object>({  className,  ...props}: BreadcrumbsProps<T>) {  return (    <BreadcrumbsPrimitive      data-slot="breadcrumb-list"      className={cn(        "flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground sm:gap-2.5",        className      )}      {...props}    />  )}
function BreadcrumbItem({  className,  children,  separatorClassName,  ...props}: BreadcrumbProps & { separatorClassName?: string }) {  return (    <BreadcrumbPrimitive      data-slot="breadcrumb-item"      className={cn("inline-flex items-center gap-1.5", className)}      {...props}    >      {composeRenderProps(children, (children, { isCurrent }) => (        <>          {children}          {!isCurrent && (            <span              data-slot="breadcrumb-separator"              role="presentation"              aria-hidden="true"              className={cn("[&>svg]:size-3.5", separatorClassName)}            >              <ChevronRightIcon />            </span>          )}        </>      ))}    </BreadcrumbPrimitive>  )}
function BreadcrumbLink({ className, render, ...props }: LinkProps) {  return (    <LinkPrimitive      data-slot="breadcrumb-link"      className={cn("transition-colors hover:text-foreground", className)}      render={render}      {...props}    />  )}
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {  return (    <span      data-slot="breadcrumb-page"      role="link"      aria-disabled="true"      aria-current="page"      className={cn("font-normal text-foreground", className)}      {...props}    />  )}
function BreadcrumbEllipsis({  className,  ...props}: React.ComponentProps<"span">) {  return (    <span      data-slot="breadcrumb-ellipsis"      role="presentation"      aria-hidden="true"      className={cn(        "flex size-5 items-center justify-center [&>svg]:size-4",        className      )}      {...props}    >      <MoreHorizontalIcon      />      <span className="sr-only">More</span>    </span>  )}
export {  Breadcrumb,  BreadcrumbList,  BreadcrumbItem,  BreadcrumbLink,  BreadcrumbPage,  BreadcrumbEllipsis,}

Usage

import {  Breadcrumb,  BreadcrumbItem,  BreadcrumbLink,  BreadcrumbList,  BreadcrumbPage,} from "@/components/ui/breadcrumb"
<Breadcrumb>  <BreadcrumbList>    <BreadcrumbItem>      <BreadcrumbLink href="/purchasing">Purchasing</BreadcrumbLink>    </BreadcrumbItem>    <BreadcrumbItem>      <BreadcrumbPage>Suppliers</BreadcrumbPage>    </BreadcrumbItem>  </BreadcrumbList></Breadcrumb>

The last BreadcrumbItem is the current page: it holds a BreadcrumbPage, not a link, and it gets no separator. Every other item holds a BreadcrumbLink.

Examples

Default

A path of links ending in the current page. Use it on pages two or more levels deep.

With icon

An icon link can stand for the first level, usually home. Give it an aria-label, because it has no visible text.

Collapsed

When the path is long, replace the middle levels with a BreadcrumbEllipsis inside a menu button. The hidden levels stay reachable from a Dropdown Menu.

Accessibility

KeyAction
TabMoves focus to the next link in the path.
ShiftTabMoves focus to the previous link.
EnterFollows the focused link.

React Aria provides:

  • An ordered list of items, with the last one marked as the current item.
  • Link behaviour on BreadcrumbLink: keyboard activation, press events and client navigation through the router.
  • A focus ring for keyboard focus only.

The component adds:

  • A nav landmark with the label "breadcrumb".
  • aria-current="page" on BreadcrumbPage.
  • Separators hidden from assistive technology.

You provide:

  • A more specific label when the page has more than one navigation landmark. Pass aria-label to Breadcrumb, which replaces the default.
  • Link text that matches the title of the page it leads to.
  • An aria-label on icon-only links and on the trigger of a collapsed path.

Guidelines

When to use

  • On pages in a hierarchy that is three or more levels deep, such as an order inside a supplier inside purchasing.
  • When users arrive from search or a shared link and need to see where they are.

When not to use

  • As the main navigation. Use a Navigation Menu or a Sidebar.
  • For a flat app with one or two levels. A back link or a page title is enough.
  • To show a history of pages the user visited. A breadcrumb shows the structure, not the history.
  • To show steps in a process. Use numbered steps.

Content

  • Use the page title for each level, in sentence case.
  • Show the whole path from the top, or collapse the middle. Do not drop the first level.
  • Keep labels short. A long title is shortened with an ellipsis in CSS, not by rewriting it.
Do

End the path with the current page as plain text.

Don’t

Don’t link the last level to itself. It has no current page and sends the user to where they already are.

API reference

The landmark. Renders a nav with aria-label="breadcrumb". It accepts every nav prop, so aria-label can be replaced.

PropTypeDefaultDescription
aria-label?string"breadcrumb"The name of the landmark.
className?stringNoneClasses merged after the base classes.

The list of items. Renders an ol through the React Aria Breadcrumbs. It accepts every Breadcrumbs prop.

PropTypeDefaultDescription
isDisabled?booleanfalseDisables every link in the path.
onAction?(key: Key) => voidNoneCalled when an item with an id is pressed.
className?stringNoneClasses merged after the base classes.

One level, with a chevron after it unless it is the current one. Renders an li through the React Aria Breadcrumb.

PropTypeDefaultDescription
id?KeyNoneIdentifies the item for onAction.
separatorClassName?stringNoneClasses for the chevron separator.
className?stringNoneClasses merged after the base classes.

A link to a level. Renders an a through the React Aria Link, so it accepts every Link prop.

PropTypeDefaultDescription
href?stringNoneThe destination. Internal paths navigate on the client through the router.
className?stringNoneClasses merged after the base classes.

The current page. Renders a span with aria-current="page" and aria-disabled="true".

PropTypeDefaultDescription
children?ReactNodeNoneThe title of the current page.
className?stringNoneClasses merged after the base classes.

A three-dot icon for collapsed levels, with the hidden text "More". It is hidden from assistive technology, so put it inside a button that has its own label.

PropTypeDefaultDescription
className?stringNoneClasses merged after the base classes.