|$ curl https://forge-ai.dev/api/markdown?path=docs/components/carousels
$cat docs/carousels-&-sliders.md
updated Recently·16 min read·published

Carousels & Sliders

CSSHTMLUIAdvanced🎯Free Tools

Scroll-snap carousels, auto-play image sliders with dot indicators and arrow navigation, multi-item responsive carousels, and card-based sliders \u2014 all pure CSS and vanilla JavaScript.

Basic Scroll Snap

The simplest carousel uses CSS scroll-snap-type and scroll-snap-align for native-feeling horizontal scrolling with snapping. No JavaScript required. The track uses flexbox with horizontal overflow, and each slide snaps to the start of the container on scroll.

scroll-snap
Live
untitled.html
HTML
1<div class="snap-carousel">
2 <div class="snap-track">
3 <div class="snap-slide" style="background:linear-gradient(135deg,#0f2027,#203a43)">
4 <div class="slide-content">
5 <span class="slide-tag">
6 01
7 </span>
8 <h3>
9 Mountain Peaks
10 </h3>
11 <p>
12 Explore the world's highest summits
13 </p>
14 </div>
15 </div>
16 <div class="snap-slide" style="background:linear-gradient(135deg,#1a0533,#2d1b69)">
17 <div class="slide-content">
18 <span class="slide-tag">
19 02
20 </span>
21 <h3>
22 Deep Ocean
23 </h3>
24 <p>
25 Dive into the unknown depths
26 </p>
27 </div>
28 </div>
29 <div class="snap-slide" style="background:linear-gradient(135deg,#0c2340,#1e5a8a)">
30 <div class="slide-content">
31 <span class="slide-tag">
32 03
33 </span>
34 <h3>
35 Northern Lights
36 </h3>
37 <p>
38 Witness the aurora borealis
39 </p>
40 </div>
41 </div>
42 <div class="snap-slide" style="background:linear-gradient(135deg,#2d1810,#5a3a28)">
43 <div class="slide-content">
44 <span class="slide-tag">
45 04
46 </span>
47 <h3>
48 Desert Dunes
49 </h3>
50 <p>
51 Traverse endless sand landscapes
52 </p>
53 </div>
54 </div>
55 </div>
56</div>
preview
Scroll Snap CSS Reference

Scroll snap is a CSS-only solution for carousel behavior. The key properties are scroll-snap-type on the container (mandatory or proximity) and scroll-snap-align on each child (start, center, or end).

scroll-snap.css
CSS
1/* Container: mandatory snap on X axis */
2.carousel-track {
3 display: flex;
4 overflow-x: auto;
5 scroll-snap-type: x mandatory;
6 scroll-behavior: smooth;
7 gap: 12px;
8}
9
10/* Each slide: snap to start */
11.carousel-slide {
12 flex: 0 0 100%;
13 scroll-snap-align: start;
14}
15
16/* Optional: hide scrollbar */
17.carousel-track::-webkit-scrollbar {
18 display: none;
19}
20.carousel-track {
21 scrollbar-width: none;
22}
Arrow Navigation

A carousel with previous/next arrow buttons that scroll to the adjacent slide. The arrows disable at boundaries and the active slide is tracked for the dot indicators. Arrow buttons overlay the carousel with absolute positioning.

arrows
Live
untitled.html
HTML
1<div class="arrow-carousel">
2 <div class="ac-track" id="ac-track">
3 <div class="ac-slide">
4 <div class="ac-card">
5 <div class="ac-img" style="background:#1a1a2e">
6 <span class="ac-num">
7 01
8 </span>
9 </div>
10 <div class="ac-info">
11 <h4>
12 Project Alpha
13 </h4>
14 <p>
15 Design system and component library
16 </p>
17 </div>
18 </div>
19 </div>
20 <div class="ac-slide">
21 <div class="ac-card">
22 <div class="ac-img" style="background:#16213e">
23 <span class="ac-num">
24 02
25 </span>
26 </div>
27 <div class="ac-info">
28 <h4>
29 Project Beta
30 </h4>
31 <p>
32 API gateway and microservices
33 </p>
34 </div>
35 </div>
36 </div>
37 <div class="ac-slide">
38 <div class="ac-card">
39 <div class="ac-img" style="background:#0f3460">
40 <span class="ac-num">
41 03
42 </span>
43 </div>
44 <div class="ac-info">
45 <h4>
46 Project Gamma
47 </h4>
48 <p>
49 Machine learning pipeline
50 </p>
51 </div>
52 </div>
53 </div>
54 <div class="ac-slide">
55 <div class="ac-card">
56 <div class="ac-img" style="background:#533483">
57 <span class="ac-num">
58 04
59 </span>
60 </div>
61 <div class="ac-info">
62 <h4>
63 Project Delta
64 </h4>
65 <p>
66 Real-time analytics dashboard
67 </p>
68 </div>
69 </div>
70 </div>
71 </div>
72 <button class="ac-arrow ac-prev" id="ac-prev" disabled>
73
74 </button>
75 <button class="ac-arrow ac-next" id="ac-next">
76
77 </button>
78 <div class="ac-dots" id="ac-dots">
79 <span class="ac-dot active">
80 </span>
81 <span class="ac-dot">
82 </span>
83 <span class="ac-dot">
84 </span>
85 <span class="ac-dot">
86 </span>
87 </div>
88</div>
preview
Auto-Play with Pause

An auto-advancing carousel that pauses on hover and resumes when the cursor leaves. A progress bar shows the time remaining before the next transition. Uses setTimeout for timing and resets the CSS animation on each slide change.

autoplay
Live
untitled.html
HTML
1<div class="auto-carousel" id="auto-carousel">
2 <div class="auto-track" id="auto-track">
3 <div class="auto-slide">
4 <div class="auto-card gradient-1">
5 <div class="auto-body">
6 <span class="auto-badge">
7 Featured
8 </span>
9 <h3>
10 Design Systems
11 </h3>
12 <p>
13 Building scalable component libraries with consistent tokens, patterns, and documentation.
14 </p>
15 <button class="auto-btn">
16 Learn More
17 </button>
18 </div>
19 </div>
20 </div>
21 <div class="auto-slide">
22 <div class="auto-card gradient-2">
23 <div class="auto-body">
24 <span class="auto-badge">
25 New
26 </span>
27 <h3>
28 Edge Computing
29 </h3>
30 <p>
31 Deploy serverless functions to 200+ edge locations worldwide for sub-millisecond latency.
32 </p>
33 <button class="auto-btn">
34 Learn More
35 </button>
36 </div>
37 </div>
38 </div>
39 <div class="auto-slide">
40 <div class="auto-card gradient-3">
41 <div class="auto-body">
42 <span class="auto-badge">
43 Popular
44 </span>
45 <h3>
46 AI Workflows
47 </h3>
48 <p>
49 Orchestrate multi-step AI pipelines with automatic retries and cost optimization.
50 </p>
51 <button class="auto-btn">
52 Learn More
53 </button>
54 </div>
55 </div>
56 </div>
57 </div>
58 <div class="auto-progress" id="auto-progress">
59 <div class="auto-bar">
60 </div>
61 </div>
62 <div class="auto-controls">
63 <button class="auto-arrow" id="auto-prev">
64
65 </button>
66 <div class="auto-dots" id="auto-dots">
67 <span class="ad active">
68 </span>
69 <span class="ad">
70 </span>
71 <span class="ad">
72 </span>
73 </div>
74 <button class="auto-arrow" id="auto-next">
75
76 </button>
77 </div>
78</div>
preview
Multi-Item Carousel

Shows multiple items at once with scroll snap. Each card snaps into place using flex: 0 0 calc(33.333% - 7px) for three visible items, and the last items fill the remaining space. Ideal for product grids and card lists.

multi-item
Live
untitled.html
HTML
1<div class="multi-carousel">
2 <div class="multi-track">
3 <div class="multi-card">
4 <div class="mc-avatar" style="background:#1a1a2e">
5 JS
6 </div>
7 <div class="mc-info">
8 <h5>
9 JavaScript
10 </h5>
11 <span>
12 24 lessons
13 </span>
14 </div>
15 </div>
16 <div class="multi-card">
17 <div class="mc-avatar" style="background:#16213e">
18 TS
19 </div>
20 <div class="mc-info">
21 <h5>
22 TypeScript
23 </h5>
24 <span>
25 18 lessons
26 </span>
27 </div>
28 </div>
29 <div class="multi-card">
30 <div class="mc-avatar" style="background:#0f3460">
31 PY
32 </div>
33 <div class="mc-info">
34 <h5>
35 Python
36 </h5>
37 <span>
38 32 lessons
39 </span>
40 </div>
41 </div>
42 <div class="multi-card">
43 <div class="mc-avatar" style="background:#533483">
44 RS
45 </div>
46 <div class="mc-info">
47 <h5>
48 Rust
49 </h5>
50 <span>
51 14 lessons
52 </span>
53 </div>
54 </div>
55 <div class="multi-card">
56 <div class="mc-avatar" style="background:#2d1810">
57 GO
58 </div>
59 <div class="mc-info">
60 <h5>
61 Go
62 </h5>
63 <span>
64 20 lessons
65 </span>
66 </div>
67 </div>
68 <div class="multi-card">
69 <div class="mc-avatar" style="background:#1a3a1a">
70 SW
71 </div>
72 <div class="mc-info">
73 <h5>
74 Swift
75 </h5>
76 <span>
77 16 lessons
78 </span>
79 </div>
80 </div>
81 </div>
82</div>
preview
Testimonial Slider

A content-focused carousel for testimonials and quotes with author details, star ratings, and smooth crossfade transitions between items. Auto-advances every 5 seconds with manual dot navigation.

testimonial
Live
untitled.html
HTML
1<div class="testi-carousel" id="testi-carousel">
2 <div class="testi-slide active" id="ts-0">
3 <div class="testi-stars">
4 ★★★★★
5 </div>
6 <blockquote class="testi-quote">
7 "This design system reduced our component development time by 60%. The token architecture is incredibly well thought out."
8 </blockquote>
9 <div class="testi-author">
10 <div class="testi-avatar">
11 SK
12 </div>
13 <div>
14 <span class="testi-name">
15 Sarah Kim
16 </span>
17 <span class="testi-role">
18 Engineering Lead, Vercel
19 </span>
20 </div>
21 </div>
22 </div>
23 <div class="testi-slide" id="ts-1">
24 <div class="testi-stars">
25 ★★★★★
26 </div>
27 <blockquote class="testi-quote">
28 "We migrated our entire frontend in 3 weeks. The component API is consistent and the documentation is outstanding."
29 </blockquote>
30 <div class="testi-author">
31 <div class="testi-avatar">
32 MR
33 </div>
34 <div>
35 <span class="testi-name">
36 Marcus Rivera
37 </span>
38 <span class="testi-role">
39 CTO, Stripe
40 </span>
41 </div>
42 </div>
43 </div>
44 <div class="testi-slide" id="ts-2">
45 <div class="testi-stars">
46 ★★★★★
47 </div>
48 <blockquote class="testi-quote">
49 "The accessibility-first approach means we don't have to retrofit a11y later. Every component works with screen readers out of the box."
50 </blockquote>
51 <div class="testi-author">
52 <div class="testi-avatar">
53 AL
54 </div>
55 <div>
56 <span class="testi-name">
57 Aisha Liang
58 </span>
59 <span class="testi-role">
60 Designer, Figma
61 </span>
62 </div>
63 </div>
64 </div>
65 <div class="testi-nav">
66 <button class="tn active" data-i="0">
67 </button>
68 <button class="tn" data-i="1">
69 </button>
70 <button class="tn" data-i="2">
71 </button>
72 </div>
73</div>
preview
Thumbnail Navigation

A main image with thumbnail strip below for direct slide selection. Clicking a thumbnail jumps to that slide and highlights the active thumbnail. The strip syncs bidirectionally with the main view via scroll position.

thumbnail
Live
untitled.html
HTML
1<div class="thumb-carousel">
2 <div class="tc-main" id="tc-main">
3 <div class="tc-big" style="background:linear-gradient(135deg,#0f2027,#203a43)">
4 <span class="tc-label">
5 Tokyo
6 </span>
7 </div>
8 <div class="tc-big" style="background:linear-gradient(135deg,#1a0533,#2d1b69)">
9 <span class="tc-label">
10 Kyoto
11 </span>
12 </div>
13 <div class="tc-big" style="background:linear-gradient(135deg,#0c2340,#1e5a8a)">
14 <span class="tc-label">
15 Osaka
16 </span>
17 </div>
18 <div class="tc-big" style="background:linear-gradient(135deg,#2d1810,#5a3a28)">
19 <span class="tc-label">
20 Hiroshima
21 </span>
22 </div>
23 </div>
24 <div class="tc-strip">
25 <button class="tc-thumb active" data-i="0">
26 <div class="tc-mini" style="background:#1a2a2f">
27 </div>
28 <span>
29 Tokyo
30 </span>
31 </button>
32 <button class="tc-thumb" data-i="1">
33 <div class="tc-mini" style="background:#1a0f33">
34 </div>
35 <span>
36 Kyoto
37 </span>
38 </button>
39 <button class="tc-thumb" data-i="2">
40 <div class="tc-mini" style="background:#0f2a4a">
41 </div>
42 <span>
43 Osaka
44 </span>
45 </button>
46 <button class="tc-thumb" data-i="3">
47 <div class="tc-mini" style="background:#3a2218">
48 </div>
49 <span>
50 Hiroshima
51 </span>
52 </button>
53 </div>
54</div>
preview
HTML Structure

The scroll-snap carousel uses a track container with scroll-snap-type: x mandatory and child slides with scroll-snap-align: start. Arrow buttons use scrollTo() for smooth transitions. Always include aria-label on navigation buttons.

carousel-structure.html
HTML
1<div class="carousel-track" style="scroll-snap-type: x mandatory">
2 <div class="carousel-slide" style="scroll-snap-align: start">
3 Slide 1
4 </div>
5 <div class="carousel-slide" style="scroll-snap-align: start">
6 Slide 2
7 </div>
8</div>
9
10<button class="prev" aria-label="Previous slide">‹</button>
11<button class="next" aria-label="Next slide">›</button>
12
13<div class="indicators" role="tablist">
14 <button role="tab" aria-selected="true" class="active"></button>
15 <button role="tab" aria-selected="false"></button>
16</div>
Best Practices

info

Use CSS scroll-snap-type for simple carousels \u2014 it provides native-feeling snap behavior with zero JavaScript. Only reach for JS-driven transitions when you need crossfade effects or complex timing control.

warning

Auto-playing carousels should always pause on hover and respect the prefers-reduced-motion media query. Some users experience motion sickness or vestibular disorders from moving content.

best practice

Include aria-labelon arrow buttons ("Previous slide" / "Next slide") and role="tablist" on dot indicator containers for screen reader accessibility.
  • Hide scrollbar with scrollbar-width: none and ::-webkit-scrollbar for a cleaner appearance across all browsers.
  • Use overflow: hidden on the carousel container to clip slides at the boundary.
  • For multi-item carousels, calculate item width as calc(100% / visibleCount - gap) to fit exactly N items per viewport.
  • Add scroll-behavior: smooth for animated scrolling between slides without JavaScript.
  • On mobile, support swipe via native touch scrolling \u2014 avoid intercepting touch events unless you need custom gestures.
  • For auto-play, use a 4-5 second interval \u2014 fast enough to maintain interest but slow enough to read the content.