Breadcrumb

The Breadcrumb component displays a navigation trail that helps users understand their location within a website or application. It provides context and allows for easy navigation to parent or ancestor pages.

Usage

<script>
  import { 
    Breadcrumb,
    BreadcrumbList,
    BreadcrumbItem,
    BreadcrumbLink,
    BreadcrumbSeparator,
    BreadcrumbPage
  } from "$lib/components/ui/breadcrumb";
</script>

<Breadcrumb>
  <BreadcrumbList>
    <BreadcrumbItem>
      <BreadcrumbLink href="/">Home</BreadcrumbLink>
    </BreadcrumbItem>
    <BreadcrumbSeparator />
    <BreadcrumbItem>
      <BreadcrumbLink href="/docs">Documentation</BreadcrumbLink>
    </BreadcrumbItem>
    <BreadcrumbSeparator />
    <BreadcrumbItem>
      <BreadcrumbPage>Breadcrumb</BreadcrumbPage>
    </BreadcrumbItem>
  </BreadcrumbList>
</Breadcrumb>

Examples

Basic Breadcrumb

A simple breadcrumb navigation showing the current path.

With Ellipsis

A breadcrumb with truncated middle sections, useful for deep hierarchies.

Custom Separator

A breadcrumb with a custom separator icon or text.

With Icons

A breadcrumb with icons for visual enhancement.

With SVG Link

A breadcrumb with a custom SVG link component.

Dynamic Breadcrumb

A breadcrumb generated dynamically based on the current route.

API Reference

Breadcrumb Components

ComponentDescription
BreadcrumbThe root container for the breadcrumb navigation.
BreadcrumbListThe ordered list that contains the breadcrumb items.
BreadcrumbItemA list item containing a breadcrumb link or current page.
BreadcrumbLinkA link to a parent or ancestor page in the navigation hierarchy.
BreadcrumbPageThe current page indicator (non-interactive).
BreadcrumbSeparatorThe separator between breadcrumb items.
BreadcrumbEllipsisAn indicator for truncated breadcrumb items.

Breadcrumb Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLElementundefinedA reference to the underlying HTML element.

BreadcrumbList Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLOlElementundefinedA reference to the underlying HTML element.

BreadcrumbItem Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLLIElementundefinedA reference to the underlying HTML element.

BreadcrumbLink Properties

PropertyTypeDefaultDescription
hrefstringundefinedThe URL the link points to.
classstringundefinedCustom CSS classes.
childSnippetundefinedOptional custom child component.
refHTMLAnchorElementundefinedA reference to the underlying HTML element.

BreadcrumbPage Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLSpanElementundefinedA reference to the underlying HTML element.

BreadcrumbSeparator Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLLIElementundefinedA reference to the underlying HTML element.

BreadcrumbEllipsis Properties

PropertyTypeDefaultDescription
classstringundefinedCustom CSS classes.
refHTMLSpanElementundefinedA reference to the underlying HTML element.

Implementation

The Breadcrumb component is implemented using semantic HTML elements for better accessibility. It uses the nav element with an aria-label="breadcrumb" for the container, an ordered list <ol> for the breadcrumb items, and appropriate ARIA attributes for the current page and separators:

<!-- Breadcrumb root component -->
<nav class={className} aria-label="breadcrumb">
  {@render children?.()}
</nav>

<!-- BreadcrumbList component -->
<ol class={cn(
  "text-muted-foreground flex flex-wrap items-center gap-1.5 break-words text-sm sm:gap-2.5",
  className
)}>
  {@render children?.()}
</ol>

<!-- BreadcrumbPage component (current page) -->
<span
  role="link"
  aria-disabled="true"
  aria-current="page"
  class={cn("text-foreground font-normal", className)}
>
  {@render children?.()}
</span>

<!-- BreadcrumbSeparator component -->
<li
  role="presentation"
  aria-hidden="true"
  class={cn("[&>svg]:size-3.5", className)}
>
  <!-- Default is ChevronRight icon -->
  <ChevronRight />
</li>

The default separator is a ChevronRight icon, but it can be customized by providing children to the BreadcrumbSeparator component. The component also supports an ellipsis indicator for long breadcrumb trails.