Skip to content

Breadcrumbs Examples

The examples below assume that you have imported the component and set up the theme.

Basic

Show the path to the current page, and keep it on one row when the space is narrow. Each child of sv-breadcrumbs becomes one item, and the items that do not fit hide behind an ellipsis button.

Drag the handle on the edge of the example to narrow it, and click the ellipsis button to expand the trail. The controls change what happens when the items do not fit, limit the items, and restyle the separator.

--back
Overflow
Items
1
1
Sets --sv-breadcrumbs-item-max-width .
Separator
Sets --sv-breadcrumbs-separator .
Fills the separator slot.
0.5em
Sets --sv-breadcrumbs-gap .
<div class="breadcrumbs-basic">
<sv-breadcrumbs>
<a href="#home">Home</a>
<a href="#electronics">Electronics</a>
<a href="#computers">Computers and Tablets</a>
<a href="#laptops">Laptops</a>
<a href="#gaming">Gaming Laptops</a>
<span>Apex Pro 16</span>
</sv-breadcrumbs>
</div>
<style>
.breadcrumbs-basic {
display: grid;
grid-template-columns: minmax(0, 34rem);
place-content: center;
}
</style>

Icons

Show an icon in an item, and use an icon as the separator. An aria-label on the link names the item that shows only an icon, and a child with slot="separator" replaces the text between the items.

<div class="breadcrumbs-icons">
<sv-breadcrumbs>
<!-- Chevron -->
<svg
fill="none"
height="1em"
slot="separator"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="1em"
>
<path d="m9 6 6 6-6 6" />
</svg>
<a aria-label="Home" href="#home">
<!-- House -->
<svg aria-hidden="true" viewBox="0 0 24 24">
<path d="M3 11.5 12 4l9 7.5M5.5 9.5V20h13V9.5" />
</svg>
</a>
<a href="#settings">Settings</a>
<a href="#account">Account</a>
<span>Profile</span>
</sv-breadcrumbs>
</div>
<style>
.breadcrumbs-icons {
svg:not([slot]) {
display: block;
inline-size: 1.25em;
block-size: 1.25em;
fill: none;
stroke: currentcolor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
}
</style>

Client-Side Routing

Build the trail from data in a client-side router, and collapse it again on each route change. The items property builds the trail from data, max-items keeps it short, and setting expanded to false collapses it.

Open a subfolder or click a link to change the route.

<div class="breadcrumbs-routing">
<sv-breadcrumbs aria-label="Folder path" max-items="3"></sv-breadcrumbs>
<button type="button" class="btn breadcrumbs-routing-open">Open a subfolder</button>
</div>
<script type="application/x-typescript" module>
import type { Breadcrumbs } from "@staticview/ui/breadcrumbs";
const FOLDER_NAMES = ["Projects", "Website", "Assets", "Images", "Icons", "Social"];
const breadcrumbs = document.querySelector<Breadcrumbs>(".breadcrumbs-routing sv-breadcrumbs")!;
const openButton = document.querySelector<HTMLButtonElement>(".breadcrumbs-routing-open")!;
const showFolder = (depth: number) => {
breadcrumbs.items = FOLDER_NAMES.slice(0, depth).map((label, index) => ({
label,
href: index < depth - 1 ? `#${index + 1}` : undefined,
}));
breadcrumbs.expanded = false;
openButton.disabled = depth === FOLDER_NAMES.length;
};
breadcrumbs.addEventListener("click", event => {
const link = (event.target as Element).closest("a");
if (!link) return;
event.preventDefault();
showFolder(Number(link.getAttribute("href")!.slice(1)));
});
openButton.addEventListener("click", () => showFolder(breadcrumbs.items.length + 1));
showFolder(5);
</script>
<style>
.breadcrumbs-routing {
display: grid;
gap: 1em;
justify-items: start;
sv-breadcrumbs {
inline-size: 100%;
}
}
</style>