1. docs
  2. components
  3. breadcrumbs

BreadCrumbs

Breadcrumbs show hierarchy and navigational context for a user’s location within an application.


Installation

Copy and paste the following code into your project.

"use client";
import {
  Breadcrumbs as RACBreadcrumbs,
  Breadcrumb as RACBreadcrumb,
} from "react-aria-components";
import type {
  BreadcrumbsProps as RACBreadcrumbsProps,
  BreadcrumbProps as RACBreadcrumbProps,
  LinkProps as RACLinkProps,
} from "react-aria-components";
import { ChevronRightIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import { Link } from "./link";

type BreadcrumbsProps<T extends object> = RACBreadcrumbsProps<T>;

function Breadcrumbs<T extends object>({ ...props }: BreadcrumbsProps<T>) {
  return (
    <RACBreadcrumbs
      {...props}
      className={cn(
        "flex flex-wrap items-center mx-0 px-0 gap-2 break-words text-sm text-foreground-muted [&_svg]:size-4 ",
        props.className
      )}
    />
  );
}

type BreadcrumbProps = Omit<RACBreadcrumbProps, "children"> &
  RACLinkProps & {
    leftSection?: React.ReactNode;
    separator?: React.ReactNode;
  };

function Breadcrumb({
  leftSection,
  className,
  separator,
  ...props
}: BreadcrumbProps) {
  return (
    <RACBreadcrumb
      {...props}
      className={cn("flex items-center gap-1 group px-0", className)}
    >
      {leftSection}
      <Link
        variant="muted"
        className="no-underline capitalize font-semibold px-0 inline-flex items-center gap-1.5 hover:text-foreground transition-colors group-last-of-type:text-foreground"
        {...props}
      />
      {separator ? (
        separator
      ) : (
        <ChevronRightIcon className="w-3 h-3 text-gray-600 dark:text-zinc-400 group-last-of-type:hidden" />
      )}
    </RACBreadcrumb>
  );
}

export { type BreadcrumbsProps, type BreadcrumbProps, Breadcrumb, Breadcrumbs };

Update the import paths to match your project setup.

Usage

Breadcrumbs provide a list of links to parent pages of the current page in hierarchical order. Breadcrumbs helps implement these in an accessible way.

  • Flexible - Support for HTML navigation links, JavaScript handled links, and client side routing.
  • Accessible - Implemented as an ordered list of links. The last link is automatically marked as the current page using aria-current.
  • Styleable - Hover, press, and keyboard focus states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.
import { Breadcrumbs } from "react-aria-components";
<Breadcrumbs>
  <a href="/home">Home</a>
  <a href="/products">Products</a>
  <a href="/products/123">Product 123</a>
</Breadcrumbs>

Anatomy

Anatomy of a Breadcrumbs component

Options

Disabled

To disable the breadcrumbs, use the isDisabled prop.

Seperator

To add a seperator between the breadcrumbs, use the separator prop.

Sections

To add sections to the breadcrumbs, use the leftSection prop.

Examples

With Router

Get BreadCrumbs directly from router ( this is Nextjs example )

Props

NameTypeDescription
leftSectionReactNodeThe left section of the breadcrumb you can place your icon here
seperatorReactNodeEdit the seperator element ( the icon towards the right ) for the breadcrumb
childrenReactNodeThe children of the breadcrumb, typically a <Link>.
idKeyA unique id for the breadcrumb, which will be passed to onAction when the breadcrumb is pressed.
classNamestringThe CSS className for the element.
styleCSSPropertiesThe inline style for the element.
NameTypeDescription
isDisabledbooleanWhether the link is disabled.
autoFocusbooleanWhether the element should receive focus on render.
hrefHrefA URL to link to. See MDN.
hrefLangstringHints at the human language of the linked URL. SeeMDN.
targetHTMLAttributeAnchorTargetThe target window for the link. See MDN.
relstringThe relationship between the linked resource and the current page. See MDN.
downloadboolean | stringCauses the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
pingstringA space-separated list of URLs to ping when the link is followed. See MDN.
referrerPolicyHTMLAttributeReferrerPolicyHow much of the referrer to send when following the link. See MDN.
routerOptionsRouterOptionsOptions for the configured client side router.
childrenReactNode | (values: LinkRenderProps & { defaultChildren: ReactNode | undefined }) => ReactNodeThe children of the component. A function may be provided to alter the children based on component state.
classNamestring | (values: LinkRenderProps & { defaultClassName: string | undefined }) => stringThe CSS className for the element. A function may be provided to compute the class based on component state.
styleCSSProperties | (values: LinkRenderProps & { defaultStyle: CSSProperties }) => CSSPropertiesThe inline style for the element. A function may be provided to compute the style based on component state.

Events

NameTypeDescription
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
onFocus(e: FocusEvent\<Target\>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent\<Target\>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.

Layout

NameTypeDescription
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

Accessibility

NameTypeDescription
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
NameTypeDescription
isDisabledbooleanWhether the breadcrumbs are disabled.
childrenReactNode | (item: T) => ReactNodeThe contents of the collection.
dependenciesany[]Values that should invalidate the item cache when using dynamic collections.
itemsIterable<T>Item objects in the collection.
classNamestringThe CSS className for the element.
styleCSSPropertiesThe inline style for the element.

Events

NameTypeDescription
onAction(key: Key) => voidHandler that is called when a breadcrumb is clicked.

Layout

NameTypeDescription
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

Accessibility

NameTypeDescription
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.