Navigation indicating the current location within a hierarchy, rendered from composed children or a data-driven items array.
Data-driven usage
Pass an items array to render breadcrumbs from data. The last item is automatically marked active.
import { Breadcrumb } from '@chassis-ui/react'
export const Example = () => {
return (
<Breadcrumb
items={[{ label: 'Home', href: '#' }, { label: 'Library', href: '#' }, { label: 'Data' }]}
/>
)
}Manual markup
<Breadcrumb> links back to each previous page in a navigation hierarchy and shows the current location within it. Compose it from <BreadcrumbItem> children instead of items for full control over each item's markup. Separators are added automatically via CSS.
import { Breadcrumb, BreadcrumbItem } from '@chassis-ui/react'
export const Example = () => {
return (
<>
<Breadcrumb>
<BreadcrumbItem active>Home</BreadcrumbItem>
</Breadcrumb>
<Breadcrumb>
<BreadcrumbItem href="#">Home</BreadcrumbItem>
<BreadcrumbItem active>Library</BreadcrumbItem>
</Breadcrumb>
<Breadcrumb>
<BreadcrumbItem href="#">Home</BreadcrumbItem>
<BreadcrumbItem href="#">Library</BreadcrumbItem>
<BreadcrumbItem active>Data</BreadcrumbItem>
</Breadcrumb>
</>
)
}Dividers
Dividers are added automatically in CSS through ::before and content. Change them by setting the local --cx-breadcrumb-divider CSS custom property, or through the $breadcrumb-divider Sass variable. The Sass variable is set as a fallback to the custom property by default, producing a global divider that can be overridden without recompiling CSS at any time. --cx-breadcrumb-divider-color colors a text divider and --cx-breadcrumb-divider-width sets the width of the space it sits in.
import { Breadcrumb, BreadcrumbItem } from '@chassis-ui/react'
export const Example = () => {
return (
<Breadcrumb style={{ '--cx-breadcrumb-divider': "'>'" } as React.CSSProperties}>
<BreadcrumbItem href="#">Home</BreadcrumbItem>
<BreadcrumbItem active>Library</BreadcrumbItem>
</Breadcrumb>
)
}Inside dir="rtl" the divider reads --cx-breadcrumb-divider-rtl instead, with the $breadcrumb-divider-rtl Sass variable as its fallback. That variable defaults to $breadcrumb-divider, so a directional divider such as > needs its mirrored counterpart set as well, or right-to-left pages show it pointing the wrong way.
Modifying the divider via Sass requires the string.quote function to generate the quotes around a string. Pass the variables when loading @chassis-ui/css's configuration, as its Sass customization guide describes. For example, to use > as the divider:
@use "sass:string";
@use "@chassis-ui/css/scss/config" with (
$breadcrumb-divider: string.quote(">"),
$breadcrumb-divider-rtl: string.quote("<")
);An embedded SVG icon also works as a divider, applied via the CSS custom property or the Sass variable. The SVG is drawn as an image, so it can't inherit the text color: set its fill to a fixed color.
import { Breadcrumb, BreadcrumbItem } from '@chassis-ui/react'
export const Example = () => {
return (
<Breadcrumb
style={
{
'--cx-breadcrumb-divider':
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='%23888888'/%3E%3C/svg%3E\")"
} as React.CSSProperties
}
>
<BreadcrumbItem href="#">Home</BreadcrumbItem>
<BreadcrumbItem active>Library</BreadcrumbItem>
</Breadcrumb>
)
}@use "@chassis-ui/css/scss/config" with (
$breadcrumb-divider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='%23888888'/%3E%3C/svg%3E")
);Removing the divider entirely takes setting --cx-breadcrumb-divider: '' (an empty string still counts as a value for a CSS custom property), or setting the Sass variable to none.
import { Breadcrumb, BreadcrumbItem } from '@chassis-ui/react'
export const Example = () => {
return (
<Breadcrumb style={{ '--cx-breadcrumb-divider': "''" } as React.CSSProperties}>
<BreadcrumbItem href="#">Home</BreadcrumbItem>
<BreadcrumbItem active>Library</BreadcrumbItem>
</Breadcrumb>
)
}@use "@chassis-ui/css/scss/config" with (
$breadcrumb-divider: none
);Accessibility
Since breadcrumbs provide navigation, an aria-label="breadcrumb" on the <nav> element explains the type of navigation implemented, and aria-current="page" on the last item marks it as the current page. <Breadcrumb> sets both of these automatically.
See the WAI-ARIA Authoring Practices for the breadcrumb pattern for more detail.
API
Breadcrumb
| Prop | Type | Default |
|---|---|---|
aria-label? | string | breadcrumb |
Accessible name of the wrapping <nav> landmark. Defaults to the English 'breadcrumb';
override it to translate the landmark, or to tell two breadcrumb trails on the same page
apart (landmarks of the same role need distinct names to be distinguishable in a screen
reader's landmark list). | ||
className? | string | — |
| A string of all className you want applied to the component. | ||
items? | BreadcrumbItemDef[] | — |
| Array of breadcrumb items for data-driven rendering. The last item is automatically marked active. When provided, children are ignored. | ||
BreadcrumbItemDef
Shape of each entry in Breadcrumb's items array (data-driven rendering).
| Prop | Type | Default |
|---|---|---|
href? | string | — |
| URL for the breadcrumb link. The last item in the array is always rendered as active (no link needed). | ||
label | ReactNode | — |
| Label for the breadcrumb item. | ||
BreadcrumbItem
| Prop | Type | Default |
|---|---|---|
active? | boolean | — |
| Toggle the active state for the component. | ||
className? | string | — |
| A string of all className you want applied to the base component. | ||
href? | string | — |
The href attribute for the inner <Link> component. | ||