webdevpuneet.com

Category Drill-Down Carousel — HTML CSS JS Snippet

Category Drill-Down Carousel · Carousels · Plain HTML, CSS & JS · Live preview

Copy & paste

Source Code

<div class="cdd-wrap">
  <div class="cdd-tabs" id="cddTabs"></div>
  <div class="cdd-viewport">
    <div class="cdd-track" id="cddTrack"></div>
  </div>
  <div class="cdd-controls">
    <button class="cdd-btn" id="cddPrev" aria-label="Previous">‹</button>
    <div class="cdd-dots" id="cddDots"></div>
    <button class="cdd-btn" id="cddNext" aria-label="Next">›</button>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Category tabs completely rebuild the slide deck, not just filter a shared pool of items
Each category can have a different number of items — the carousel's length adapts automatically
Switching categories always resets position to the first item, preventing an out-of-range index
Dots are regenerated to match the active category's own item count on every switch
One nested data structure drives both the tab labels and each category's own slide content
Standard arrow/dot/keyboard navigation works identically regardless of which category is active

About this UI Snippet

Category Drill-Down Carousel — Tabs That Rebuild the Deck, Not Just Filter It

Screenshot of the Category Drill-Down Carousel snippet rendered live

This is a two-level navigation structure disguised as one carousel: a row of category tabs sits above a slide deck, and clicking a tab doesn't filter the *existing* slides — it discards them and builds an entirely *new* deck from that category's own item list. Unlike the Filter-Reactive Carousel elsewhere in this library (which filters one flat pool of items down by tag), this one's categories don't share a pool at all — "Audio" has two items, "Gaming" has three, and the carousel's own length, dot count, and bounds all adjust to match whichever category is active.

Slides are rebuilt, dots are rebuilt, position always resets

switchCategory() does three things every time: sets activeCat, resets current back to 0, and calls buildSlides(), which clears and regenerates *both* the slide track and the dots from DATA[activeCat].items. That reset-to-zero is deliberate — carrying over an index from a 3-item category into a 2-item one could point at a slide that no longer exists, so switching categories always lands cleanly on that category's first item.

One data structure, two levels of navigation

DATA is a plain object keyed by category id, each holding a label (for the tab) and an items array (for the slides) — the tabs are generated from Object.keys(DATA), and the slide deck is generated from whichever category's items is currently active. Adding a whole new category, with its own independent item count, is one new key in that object — no other code changes.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSThree category tabs appear above a carousel showing "Audio"'s two items, starting on the first.
  2. 2
    Click "Gaming"The whole deck rebuilds — now three items, three dots, reset to the first one.
  3. 3
    Navigate within a categoryArrows, dots, and arrow keys move through that category's own items normally.
  4. 4
    Switch categories againPosition always resets to the first item of whichever category you land on.
  5. 5
    Add a fourth categoryAdd one new key to DATA with its own label and items array — a matching tab appears automatically.

Real-world uses

Common Use Cases

🛍️
Multi-category product showcases
Browse genuinely separate product sets with tabs that discard the current slides and build a new deck, instead of filtering a shared pool.
🎨
Portfolio by discipline
Show design, code and photography work in their own carousels, each with a different item count that the carousel adapts to automatically.
❓
Help centre topic browsers
Give each help topic its own set of articles, resetting to the first item on every switch so the position is never out of range.
🍽️
Menu and catalogue sections
Present restaurant menu sections or catalogue departments, with the dots regenerated to match the active category's own item count.

Got questions?

Frequently Asked Questions

Filter-Reactive Carousel filters ONE shared pool of items down by a tag — the underlying item set never changes, only which subset is shown. This snippet's categories are genuinely separate item lists with independent counts; switching categories discards the old deck and builds a completely different one.

Because each category can have a different number of items, carrying over an index from a longer category into a shorter one could point past the end of the new deck. Resetting to 0 guarantees the carousel always lands on a valid, existing slide.

Add one new key to the DATA object with its own label and its own items array (icons/titles/backgrounds) — a matching tab is generated automatically from Object.keys(DATA), with no other code changes required.

Yes — just include the same item object (or an equivalent duplicate) in both categories' items arrays; the data model treats each category's list independently, so overlap is entirely allowed.

Tabs, arrows, and dots are all real, labeled buttons, and the whole carousel is operable via Left/Right arrow keys; for full accessibility, add aria-selected to the active tab and consider role="tablist"/role="tab" semantics on the tab row.