Breadcrumb Dropdown — Free HTML CSS JS Collapsed Path Nav
Breadcrumb Dropdown · Navigation · Plain HTML, CSS & JS · Live preview
Copy & paste
Source Code
<nav class="bd-nav" aria-label="Breadcrumb">
<ol class="bd-crumbs" id="bdCrumbs">
<li><a href="#">Home</a></li>
<li class="bd-collapsed">
<button type="button" class="bd-more" id="bdMore" aria-haspopup="true" aria-expanded="false" aria-label="Show hidden path">…</button>
<ul class="bd-menu" id="bdMenu" role="menu">
<li role="none"><a role="menuitem" href="#">Workspace</a></li>
<li role="none"><a role="menuitem" href="#">Projects</a></li>
<li role="none"><a role="menuitem" href="#">Marketing site</a></li>
</ul>
</li>
<li><a href="#">Pages</a></li>
<li><a href="#">Landing</a></li>
<li aria-current="page">Hero section</li>
</ol>
</nav>*{box-sizing:border-box;margin:0;padding:0}
body{font-family:system-ui,-apple-system,sans-serif;background:#0d0f18;display:flex;justify-content:center;align-items:center;min-height:100vh;padding:24px}
.bd-nav{background:#151926;border:1px solid #232838;border-radius:12px;padding:10px 14px}
.bd-crumbs{list-style:none;display:flex;align-items:center;flex-wrap:wrap;gap:2px;font-size:14px}
.bd-crumbs li{display:flex;align-items:center}
/* Chevron separator before every item except the first. */
.bd-crumbs li:not(:first-child)::before{content:'';width:7px;height:7px;border-right:1.6px solid #56607a;border-bottom:1.6px solid #56607a;transform:rotate(-45deg);margin:0 8px;flex-shrink:0}
.bd-crumbs a{color:#9aa3bb;text-decoration:none;padding:4px 7px;border-radius:7px;transition:background .14s,color .14s;white-space:nowrap}
.bd-crumbs a:hover{background:#1e2334;color:#dfe4f2}
.bd-crumbs li[aria-current="page"]{color:#fff;font-weight:600;padding:4px 7px}
.bd-collapsed{position:relative}
.bd-more{background:#1e2334;border:0;color:#9aa3bb;font-size:14px;font-weight:700;line-height:1;padding:5px 9px;border-radius:7px;cursor:pointer;letter-spacing:1px}
.bd-more:hover{color:#dfe4f2}
.bd-menu{position:absolute;top:calc(100% + 8px);left:0;list-style:none;background:#1b2030;border:1px solid #2b3245;border-radius:11px;padding:6px;min-width:170px;box-shadow:0 16px 40px rgba(0,0,0,.45);opacity:0;transform:translateY(-6px) scale(.97);transform-origin:top left;pointer-events:none;transition:opacity .16s,transform .16s;z-index:5}
.bd-menu.is-open{opacity:1;transform:none;pointer-events:auto}
.bd-menu a{display:block;color:#c3cadb;padding:8px 11px;border-radius:8px;font-size:13px;white-space:nowrap}
.bd-menu a:hover{background:#252c40;color:#fff}var more = document.getElementById('bdMore');
var menu = document.getElementById('bdMenu');
function close() {
menu.classList.remove('is-open');
more.setAttribute('aria-expanded', 'false');
}
function toggle() {
var open = menu.classList.toggle('is-open');
more.setAttribute('aria-expanded', open ? 'true' : 'false');
}
more.addEventListener('click', function (e) { e.stopPropagation(); toggle(); });
// Close on outside click and on Escape.
document.addEventListener('click', function (e) {
if (!menu.contains(e.target) && e.target !== more) close();
});
document.addEventListener('keydown', function (e) { if (e.key === 'Escape') close(); });Extend with AI
Take This Snippet Further With AI
The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.
What's included
Features
About this UI Snippet
Breadcrumb Dropdown — Collapse Deep Paths Without Losing Them

The breadcrumb dropdown solves the problem of long navigation trails: instead of wrapping a deep path across several lines, the middle segments collapse into a single "…" button that opens a menu of the hidden levels. This snippet builds it with a semantic ordered list, CSS, and a small vanilla JavaScript dropdown controller.
A semantic, accessible trail
The breadcrumb is a real <nav aria-label="Breadcrumb"> wrapping an ordered list, with the current page marked aria-current="page" and rendered as plain text rather than a link. This is the structure search engines and screen readers expect from a breadcrumb, so the collapse is an enhancement layered on top of correct semantics, not a replacement for them.
CSS chevron separators
The arrows between crumbs aren't characters or images — each non-first <li> draws a chevron with a ::before made from two borders rotated 45°. Generating separators in CSS means they never get selected or copied with the text, scale crisply, and recolour with a single property. The trail uses flex with flex-wrap, so on a truly tiny screen it can still wrap gracefully as a fallback.
The collapsed middle
The middle segment is a bd-collapsed list item holding a "…" button and a hidden menu of the levels it represents. Keeping the hidden crumbs in the DOM (inside the dropdown) rather than removing them means the full path is still available to anyone who wants it — you've folded the trail, not truncated it. The button carries aria-haspopup and aria-expanded so assistive tech knows it opens a menu and whether it's open.
The dropdown mechanics
Clicking "…" toggles an is-open class that fades and scales the menu in from its top-left origin with a short transition; pointer-events are disabled while closed so the hidden menu never blocks clicks. The controller closes the menu on an outside click (using menu.contains to ignore clicks inside it) and on the Escape key — the two dismissals every dropdown should support. stopPropagation on the button prevents its own click from immediately triggering the outside-click close.
Why collapse the middle, not the ends
The first crumb (home/root) and the last two (parent and current page) are the most useful for orientation, so those stay visible and only the deep middle folds away. This mirrors how file managers and IDEs handle long paths, keeping the trail compact while preserving the context that matters.
Customizing it
Choose how many crumbs to keep on each side before collapsing, restyle the chevrons and menu, or build the list dynamically and only insert the dropdown when the path exceeds a length. Pair it with a breadcrumb, a nested dropdown, or a sidebar nav.
Step by step
How to Use
- 1Paste HTML, CSS, and JSA breadcrumb renders with a … in the middle.
- 2Click the …A menu of the hidden path levels opens.
- 3Click outsideThe menu closes; Escape closes it too.
- 4Follow a crumbEach link navigates to that level.
- 5Choose what collapsesDecide how many crumbs stay on each side.
- 6Recolor the chevronsEdit the ::before border colors.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
The first crumb (root) and the last two (parent and current page) give the most orientation, so they stay visible and only the deep middle folds into the … menu. This mirrors how file managers and IDEs handle long paths, keeping the trail compact while preserving the context that matters most.
Yes. The collapsed crumbs stay in the DOM inside the dropdown rather than being removed, so the full path is available to anyone who opens the menu — you fold the trail rather than truncate it. The toggle button carries aria-haspopup and aria-expanded so assistive tech knows it opens a menu and its state.
Each non-first list item draws a chevron with a ::before made from two borders rotated 45 degrees. Generating them in CSS means the arrows are never selected or copied with the text, scale crisply, and recolour with one property — cleaner than slash characters or separator images.
Clicking … toggles an is-open class that fades and scales the menu in. A document click handler closes it when the click is outside the menu, using menu.contains to ignore inside clicks, and an Escape keydown also closes it. stopPropagation on the button keeps its own click from instantly triggering the outside-click close.
Render the crumbs from a path array and, when it exceeds a length, slice out the middle into the dropdown while keeping the first and last items visible. Hold an open boolean in state for the menu, and add document listeners for outside-click and Escape in a mount effect with cleanup. The chevron and menu CSS port unchanged.
Yes. While the Breadcrumb Dropdown snippet gives you one pattern to copy, the free Responsive Navbar Builder at webdevpuneet.com/navbar-builder/ designs a whole navigation bar: logo, links and dropdown menus, a mobile hamburger menu (dropdown panel, slide-in drawer or full screen) and a scroll effect (sticky, shrink, hide on scroll or transparent). It has six presets, a live preview that runs the real code, and exports HTML + CSS + vanilla JS, React, Tailwind, Vue 3 or Angular — or you can click Fork & Edit to keep editing it in My Code.