A responsive breadcrumb built with Tailwind CSS and a small vanilla JavaScript controller. Deep trails such as documentation sites, file managers, admin panels and design system docs keep the first level and the current page visible, while the levels in between collapse into a dropdown behind a dots button.
How it works
The root is a nav.bcd-trail with aria-label="Breadcrumb". Inside, the ol.bcd-list holds one li per level, each marked data-bcd-item, plus a hidden li.bcd-more that contains the .bcd-toggle button and an empty ul.bcd-menu. The last item is a span with aria-current="page".
On DOMContentLoaded the script runs a layout pass for every .bcd-trail. It shows all levels, adds the .bcd-measuring class so that no item may shrink, and then hides middle levels one by one, starting next to Home, while the list is wider than the bar (scrollWidth > clientWidth) or while more levels are visible than data-bcd-max-visible allows. Hidden levels are rebuilt as links inside .bcd-menu, each with a small .bcd-menu-depth tree line indented by its depth. A ResizeObserver repeats the pass whenever the width of the bar changes, so the trail expands again on wider screens. Without JavaScript all levels stay visible in one row.
Clicking .bcd-toggle opens or closes the menu and flips aria-expanded; the button turns solid violet through the aria-expanded: variant. Arrow Down opens the menu and focuses the first link, Arrow Up/Down, Home and End move between links, and Escape closes it and returns focus to the button. Clicking outside or tabbing away also closes it.
Customization
data-bcd-max-visibleon.bcd-trail: the maximum number of levels shown before collapsing; remove it to collapse only when the trail does not fit.bg-violet-600on thearia-current="page"item: change the color of the current-page pill or usefont-semibold text-slate-900for a plain look.- The separator
svgpathm8 5 5 5-5 5: replace it with a slash (M13 4 7 16) for slash separators. w-60on.bcd-menu: widen the dropdown for long level names..bcd-menu ainstyle.css: change hover color, padding or font weight of the dropdown links..bcd-menu-depthinstyle.css: hide it withdisplay: nonefor a flat list without tree lines.rounded-2xl bg-white/90on.bcd-trail: remove them for a borderless breadcrumb inside a page header.
Use cases
- Documentation sites: long section paths keep the first level and current page visible while middle levels fold into a dropdown
- File managers and cloud storage: deeply nested folder trails stay on one row and expand again when the window grows
- Admin panels: users jump back to any parent screen from the dots menu, using the keyboard if they prefer
- Design system docs: a collapsing trail avoids wrapping on narrow screens while still exposing every level
Accessibility
The trail is a nav landmark with an ordered list, and the current page uses aria-current="page". The dots button uses the disclosure pattern with aria-expanded and aria-controls; its visually hidden .bcd-label is updated to read, for example, "Show 3 hidden levels". Separators and icons are aria-hidden. All links and the button show violet focus outlines, and the menu animation is disabled under prefers-reduced-motion: reduce.
Usage notes
For several breadcrumbs on one page, give each .bcd-menu a unique id and point the toggle's aria-controls to it.