Breadcrumb

Breadcrumb trails for React built with the Breadcrumb components, with custom separators, truncated labels, collapsed steps, sideways scrolling, and step menus.

Examples

export function Trail({ steps }) {
  return (
    <Breadcrumb aria-label="Breadcrumb">
      {steps.map((step) => renderStep(step))}
    </Breadcrumb>
  );
}

Overview

These examples build breadcrumb trails with the Ariakit UI Breadcrumb components. A trail shows where a page sits in a hierarchy, and links to each level above it. The steps wrap to more rows when they run out of room, so nothing is hidden by default.

The gallery starts with a trail that has a home icon as its first step. Then it shows other separators, labels that clip with a tooltip, a deep trail with collapsed steps, and icons on the steps. Another example shows a trail in a sticky page header. Two examples switch to a neighbor of the current step with ComboboxSelect. The last three show a row that scrolls sideways, a file path in a file viewer, and labels that load after the page.

Components

Breadcrumb renders a navigation landmark with an ordered list. BreadcrumbLink renders a step that links to a level above, BreadcrumbText renders a level without a page of its own, such as a category, as text, and BreadcrumbCurrent renders the current page as text. Each one renders its own list item. Set separator on each step after the first to put a BreadcrumbSeparator before it. Inside a BreadcrumbItem, set separator on the item instead, because the step there has item={false}. The steps are written out, with no shared state, so the trail also renders on the server with no hydration, such as in an Astro page.

The steps extend button with quieter defaults. They show no surface, the links get full ink and an underline on hover, and their text can be selected. All the button variants still work. Set $hoverOffset or another layer hover variant to show a hover surface instead of the underline, or $p and $px to change the padding. The first step hangs by its side padding, so its content lines up with the text around the trail at any slot size. A step that starts a later row keeps its padding, because CSS can’t select it. Set $gap on Breadcrumb to change the space between the steps.

BreadcrumbSeparator extends the separator of button groups and tabs. Pass its props to separator, such as separator={{ $kind: "chevron" }}, and set $kind to slash, chevron, or pipe on each step, because the steps share no state. Set $kind="none" to show your own content in its children. A separator hides beside a control that paints a surface on hover or keyboard focus, such as a step with $hoverOffset, when the gap leaves too little room for both. A step with no hover surface keeps its separators on hover. A PopoverDisclosure with $selectedOffset or $selectedPush keeps a surface while its popover is open, so its separators hide during that time too. In an item with more than one control, only the control that faces the separator counts. Set $shy to true or false to change this.

Put the text of a step in a BreadcrumbLabel and set $truncate on the label to clip it to one line. The row then stops wrapping, because a row that can wrap moves a step to the next line and doesn’t clip it. The other steps stay whole, so choose the steps that can lose text. The longest labels clip first, and short labels keep all of their text as long as they can. A clipped label keeps room for a letter and an ellipsis. If the steps still don’t fit, the row cuts off the last ones, so clip more steps or use $scroll. A flex item doesn’t shrink below its content by default, so add min-w-0 to an element around the trail that is a flex item.

Also put the text beside a BreadcrumbSlot in a BreadcrumbLabel, because the gaps and the slot margins need an element on each side.

Set $scroll on Breadcrumb to keep one row that scrolls sideways. The row starts at the end of the trail, so the current step shows without script, and it stays there when the trail grows. Its scroll position is 0 at the end of the trail and goes negative toward the start. The first step doesn’t hang here, because the scroll container would clip it.

Use BreadcrumbItem for a step with more than one element, such as a link beside a button, and set item={false} on the BreadcrumbLink, BreadcrumbText, or BreadcrumbCurrent inside it.

Accessibility

Give each Breadcrumb a name with aria-label or aria-labelledby, such as “Breadcrumb”, because a page can have more than one navigation landmark.

BreadcrumbCurrent has aria-current="page". BreadcrumbText has no aria-current, so a level without a page doesn’t read as the current page. To keep the current step as a link, render a BreadcrumbLink with currentUrl or aria-current="page". This adds a tab stop that goes nowhere new.

BreadcrumbSeparator is a list item with aria-hidden, so its mark stays out of the accessibility tree. A step with only a slot needs a name from aria-label, as in the first example. A clipped label stays in the DOM, so screen readers read all of it, but other users need a tooltip to see it, as in the Truncated Labels example. There, the label renders through TruncatedText, so the tooltip shows only while the label clips.

The step menu examples use items with render={<a />}, so they navigate on Enter and open in a new tab on Cmd-click. Assistive technology reads them as options, not links. Pass the current page as selectedValue, with no setSelectedValue. Typing on the closed trigger then changes nothing, so its label can’t disagree with the page. Name the trigger after what it does, such as “Switch section”, so that people know a choice goes to another page.