Breadcrumb
Hierarchy trail that collapses long paths and works with any router link.
$
pnpm dlx shadcn@latest add https://lodeui.com/r/breadcrumb.jsoncomponents/examples/breadcrumb-demo.tsx
"use client";
import { Folder, Home } from "lucide-react";
import { Breadcrumb } from "@/components/ui/breadcrumb";
export default function BreadcrumbDemo() {
return (
<div className="space-y-4">
<Breadcrumb items={[{ label: "Home", href: "#", icon: <Home /> }, { label: "Projects", href: "#" }, { label: "Checkout" }]} />
<Breadcrumb maxItems={4} items={[{ label: "Acme", href: "#" }, { label: "Engineering", href: "#" }, { label: "Payments", href: "#" }, { label: "Services", href: "#", icon: <Folder /> }, { label: "retry.ts" }]} />
</div>
);
}When to use
- Showing where a page sits in a hierarchy.
When not to use
- Flat sites with one level.
Installation
$
pnpm dlx shadcn@latest add https://lodeui.com/r/breadcrumb.json1Install the dependencies
npm install lucide-react2Copy the source into your project
components/ui/breadcrumb.tsximport * as React from "react"; import { ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; export interface Crumb { label: React.ReactNode; href?: string; icon?: React.ReactNode; } export interface BreadcrumbProps { items: Crumb[]; /** Collapse middle items into "…" beyond this many. */ maxItems?: number; /** Render links with your router, e.g. Next.js Link. */ linkAs?: React.ElementType; className?: string; } export function Breadcrumb({ items, maxItems = 5, linkAs: LinkTag = "a", className }: BreadcrumbProps) { const collapsed = items.length > maxItems ? [items[0], { label: "…" }, ...items.slice(-(maxItems - 2))] : items; return ( <nav aria-label="Breadcrumb" className={className}> <ol className="flex flex-wrap items-center gap-1.5 text-sm text-muted-foreground"> {collapsed.map((item, i) => { const last = i === collapsed.length - 1; return ( <li key={i} className="flex items-center gap-1.5"> {item.href && !last ? ( <LinkTag href={item.href} className="flex items-center gap-1.5 rounded transition-colors hover:text-foreground [&_svg]:size-3.5"> {item.icon} {item.label} </LinkTag> ) : ( <span aria-current={last ? "page" : undefined} className={cn("flex items-center gap-1.5 [&_svg]:size-3.5", last && "font-medium text-foreground")}> {item.icon} {item.label} </span> )} {!last && <ChevronRight className="size-3.5 opacity-60" aria-hidden />} </li> ); })} </ol> </nav> ); }
Usage
Import it from @/components/ui/breadcrumb after installing.
example.tsx
import Link from "next/link";
import { Breadcrumb } from "@/components/ui/breadcrumb";
export function Trail() {
return <Breadcrumb linkAs={Link} items={[{ label: "Projects", href: "/projects" }, { label: "Atlas", href: "/projects/atlas" }, { label: "Settings" }]} />;
}API reference
Breadcrumb
A nav of links; middle items collapse into an ellipsis menu when there are too many.
| Prop | Type | Default | Description |
|---|---|---|---|
| items | { label; href?; icon? }[] | – | The last item is the current page. |
| maxItems | number | 5 | Collapse beyond this. |
| linkAs | ElementType | "a" | Your router's link, e.g. Next.js Link. |
Keyboard interactions
| Keys | Action |
|---|---|
| Tab | Move between links |
Accessibility
- nav with aria-label="Breadcrumb"; the current page has aria-current="page".
- Separators are aria-hidden.
Responsive behavior
- Lower maxItems on phones to keep it on one line.
Performance
- Static links.
Notes for AI
- Pass Next.js Link as linkAs for client navigation.
This page as Markdown, for assistants and coding agents:
/components/breadcrumb/markdownThe full library index for assistants is at /llms.txt.
Lode222 doc pagesllms.txt