suiss/ui · Component
Breadcrumb
A trail of links that shows where the current page sits in the site hierarchy.
Breadcrumb is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
A Breadcrumb is a labelled nav that contains a BreadcrumbList. The list holds BreadcrumbItem parts separated by BreadcrumbSeparator parts. Each item contains either a BreadcrumbLink to an ancestor page or, for the last item, a BreadcrumbPage for the current page. Use BreadcrumbEllipsis inside an item to stand in for collapsed levels.
Use breadcrumbs in deep hierarchies so people can see their location and move up quickly. For top-level navigation between sections, use a navigation menu or tabs.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Breadcrumb:
Examples
With home icon
Replace the first link's text with a home icon. An icon-only link needs an aria-label.
With ellipsis
Put a BreadcrumbEllipsis inside an item to stand in for collapsed middle levels.
Custom separator
Pass children to BreadcrumbSeparator to use a slash instead of the default caret.
Accessibility
Breadcrumbrenders anavwitharia-label="breadcrumb".BreadcrumbPagesetsaria-current="page".- Separators have
role="presentation"andaria-hidden="true", so only items are announced as list items. BreadcrumbEllipsishides its icon and includes visually hidden text,Moreby default; pass children to change it.- Only links are in the tab order; the ellipsis and current page are skipped.
API Reference
Breadcrumb
The nav landmark that wraps the trail.
Also accepts the props of React.ComponentProps<"nav">.
BreadcrumbList
The ordered list of items.
Also accepts the props of React.ComponentProps<"ol">.
BreadcrumbItem
A single step in the trail.
Also accepts the props of React.ComponentProps<"li">.
BreadcrumbLink
A link to an ancestor page.
Also accepts the props of useRender.ComponentProps<"a">.
BreadcrumbLink renders an a by default. Use the render prop to render your router's link component: render={<Link href="/" />}.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of React.ComponentProps<"a">.
BreadcrumbLink renders an a by default. Set asChild and pass your router's link component as the child to render it instead.
| Prop | Type | Default |
|---|---|---|
render | (props: React.HTMLAttributes<HTMLElement>) => React.ReactNode | — |
Also accepts the props of React.ComponentProps<"a">.
BreadcrumbLink renders an a by default. Pass a render function that returns your router's link component with the props it receives.
Ancestor links use text-muted-foreground and the current page uses text-foreground.
BreadcrumbPage
The current page, rendered as plain text.
Also accepts the props of React.ComponentProps<"span">.
BreadcrumbSeparator
A decorative divider between items.
Also accepts the props of React.ComponentProps<"li">.
Place a BreadcrumbSeparator between items as its own sibling, not inside a BreadcrumbItem. It renders a caret by default, which flips in right-to-left layouts; pass children to use a different separator.
BreadcrumbEllipsis
A placeholder for collapsed levels, with a screen-reader label.
Also accepts the props of React.ComponentProps<"span">.
Each part sets a data-slot, such as breadcrumb-list or breadcrumb-ellipsis, for styling.