Breadcrumbs

Alpha

Accessible breadcrumb navigation. Renders a <nav aria-label> landmark with an ordered list of links, marking the last item aria-current="page". Supports collapsible middle items via maxItems with a keyboard-accessible expand button.

Import

import { Breadcrumbs } from "@compa11y/react";

Usage

Example.tsx
import { Breadcrumbs } from "@compa11y/react";

// Basic
function BasicExample() {
  return (
    <Breadcrumbs
      items={[
        { label: "Home", href: "/" },
        { label: "Products", href: "/products" },
        { label: "Model X" },
      ]}
    />
  );
}

// Custom separator
function CustomSeparator() {
  return (
    <Breadcrumbs
      items={[
        { label: "Home", href: "/" },
        { label: "Docs", href: "/docs" },
        { label: "Breadcrumbs" },
      ]}
      separator="›"
    />
  );
}

// Collapsible (shows first + last two, hides middle behind "…")
function CollapsibleExample() {
  return (
    <Breadcrumbs
      items={[
        { label: "Home", href: "/" },
        { label: "Category", href: "/category" },
        { label: "Sub-category", href: "/category/sub" },
        { label: "Product", href: "/category/sub/product" },
        { label: "Model X" },
      ]}
      maxItems={3}
      ariaLabel="Product breadcrumb"
    />
  );
}

Features

  • <nav> landmark with aria-label (default: "Breadcrumb")
  • aria-current="page" automatically applied to the last item
  • Separators are aria-hidden — purely visual
  • Collapsible middle items via maxItems with an accessible expand button
  • Focus moves to the first revealed item after expanding
  • Optional icon support per crumb (aria-hidden wrapper)
  • forwardRef support
  • CSS variable customization

Props

Breadcrumbs component props
PropTypeDefaultDescription
itemsBreadcrumbItem[]-Ordered list of crumbs. The last item is treated as the current page (aria-current="page")
ariaLabelstring"Breadcrumb"Accessible name for the <nav> landmark
separatorReact.ReactNode"/"Visual separator between items — string or any React node
maxItemsnumber0Collapse middle items when the trail exceeds this count. 0 = never collapse
unstyledbooleanfalseRemove all inline styles; useful when applying your own CSS

Sub-components

BreadcrumbItem

BreadcrumbItem props
PropTypeDefaultDescription
labelstring-Visible text for the crumb
hrefstring-Navigation target. Omit for the current page (last item)
iconReact.ReactNode-Optional decorative icon rendered before the label (wrapped in aria-hidden)

Keyboard Interactions

Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
Keyboard shortcuts for Breadcrumbs
KeyAction
TabMoves focus between breadcrumb links and the expand button
Enter / SpaceActivates a link or the expand button

CSS Customization

Override these CSS custom properties to customize the appearance.

CSS custom properties for Breadcrumbs
VariableDescriptionDefault
--compa11y-breadcrumbs-link-colorColor of breadcrumb links#0066cc
--compa11y-breadcrumbs-current-colorColor of the current page iteminherit
--compa11y-breadcrumbs-separator-colorColor of the separator#999
--compa11y-breadcrumbs-separator-paddingHorizontal padding around each separator0.375rem