Source Code

<div class="container py-5">
  <p class="text-muted small mb-3">Click "+ Add level" a few times to grow the trail past 4 segments and watch the middle ones collapse into a "…" dropdown.</p>
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb bsbc-trail" id="bsbcTrail">
      <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
      <li class="breadcrumb-item"><a href="javascript:void(0)">Docs</a></li>
      <li class="breadcrumb-item"><a href="javascript:void(0)">Guides</a></li>
      <li class="breadcrumb-item active" aria-current="page">Getting Started</li>
    </ol>
  </nav>
  <button class="btn btn-sm btn-outline-dark" id="bsbcAdd">+ Add level</button>
  <button class="btn btn-sm btn-outline-secondary" id="bsbcReset">Reset</button>
</div>

Bootstrap Breadcrumb Trail with Dropdown Overflow — Free Snippet

Bootstrap Breadcrumb Trail with Dropdown Overflow · Navigation · Plain HTML, CSS & JS · Live preview

What's included

Features

Real Bootstrap 5.3 breadcrumb and Dropdown components, loaded from the actual CDN
Automatically collapses middle segments into a "…" dropdown once the trail exceeds 4 levels
Rebuilds the visible/hidden split from scratch on every change — never drifts out of sync
First and last two segments always stay visible, the ones a visitor most needs to see
Dropdown list of hidden segments uses Bootstrap's real Dropdown, not a custom popover
Works at any trail depth — the collapse logic has no hardcoded segment count

About this UI Snippet

Bootstrap Breadcrumb Trail with Dropdown Overflow — HTML, CSS & JavaScript

Screenshot of the Bootstrap Breadcrumb Trail with Dropdown Overflow snippet rendered live

A breadcrumb trail five or six levels deep stops being useful — it wraps, it crowds the page, and the first and last segments (the ones a visitor actually cares about) get lost in the middle. This snippet uses real Bootstrap 5.3's .breadcrumb component and rebuilds it every time a segment is added: once there are more than four segments, everything except the first and the last two collapses into a single "…" item using Bootstrap's real Dropdown component, so the trail always stays exactly four visible items wide no matter how deep the real path goes.

The render function is intentionally non-incremental — it removes any existing overflow dropdown and rebuilds the visible/hidden split from scratch on every change, which is what guarantees the collapsed trail can never drift out of sync with the actual path as levels are added or removed.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet's HTML, CSS, and JS to an AI coding assistant like Claude and ask it to make the overflow threshold responsive (collapsing at 3 segments on mobile, 5 on desktop), or to add breadcrumb structured data (BreadcrumbList JSON-LD) generated from the same trail array for SEO. It's also a good exercise to ask the assistant to drive the whole trail from a single array of {label, href} objects instead of manipulating li elements directly.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a Bootstrap 5.3 breadcrumb trail that collapses overflow into a dropdown, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble Bootstrap.

Requirements:
- A real Bootstrap breadcrumb component (ol.breadcrumb / li.breadcrumb-item) that can grow to any number of segments.
- Once the trail exceeds 4 segments, everything except the first segment and the last two must collapse into a single "…" item using Bootstrap's real Dropdown component (data-bs-toggle="dropdown"), listing the hidden segments as dropdown-item links.
- The collapse/expand logic must fully recompute which segments are visible vs. hidden every time the trail changes (add or remove a segment), rather than incrementally patching the DOM, so it can never drift out of sync with the actual path.
- Include working "add a level" and "reset" controls to demonstrate the collapsing behavior interactively.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads a 4-segment breadcrumb.
  2. 2
    Add a levelClick "+ Add level" — a 5th segment appears, and the middle segments collapse into a "…" dropdown.
  3. 3
    Open the dropdownClick the "…" — Bootstrap's real Dropdown component shows the hidden middle segments as links.
  4. 4
    Add more levelsKeep clicking "+ Add level" — the dropdown's hidden list grows while the visible trail stays exactly four items.
  5. 5
    ResetClick "Reset" to return to the original 4-segment trail.

Real-world uses

Common Use Cases

Documentation and file-browser style navigation
Deep folder or doc hierarchies routinely exceed four levels — this keeps the trail usable instead of wrapping across two lines.
Learning the breadcrumb-overflow pattern
A concrete implementation of a well-known UX pattern (used in macOS Finder, GitHub, and many admin panels) built on real Bootstrap components.
E-commerce category breadcrumbs
Deeply nested product categories (Home > Electronics > Audio > Headphones > Wireless > ...) benefit from the same collapse behavior.
Admin panels with nested resource views
Reuse this pattern for breadcrumbs in a CMS or dashboard where resources can be nested arbitrarily deep.

Got questions?

Frequently Asked Questions

Real Bootstrap 5.3 — the "…" overflow item uses the actual Dropdown component via data-bs-toggle="dropdown", the same component used for any standard Bootstrap dropdown menu.

Once the trail has more than 4 segments. Change the "4" comparisons in the render() function to adjust that threshold.

No — render() recomputes which segments are hidden every time it runs, from whatever the current trail actually contains, so it's always accurate rather than a stale snapshot.

Yes — the breadcrumb-item and dropdown-item anchors already exist; set their href to real URLs (or wire click handlers to your router) instead of javascript:void(0).

Yes — the collapse logic has no hardcoded maximum; however many segments exist beyond the first and last two all get folded into the same overflow dropdown.