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

Carousels & Sliders

CSSHTMLTailwindBootstrapUIAdvanced🎯Free Tools
Introduction

Carousels and sliders present multiple pieces of content in a shared viewport. This guide covers production-ready patterns in plain HTML/CSS, Tailwind CSS, and Bootstrap — including scroll-snap, arrow/dot navigation, auto-play, multi-item layouts, testimonials, thumbnails, hero sliders, and accessibility.

info

Prefer CSS scroll-snap-type for native-feeling carousels without JavaScript. It supports touch, keyboard, and momentum scrolling for free.
Basic Scroll Snap

A CSS-only horizontal carousel using scroll-snap-type: x mandatory and hidden scrollbars. Each slide snaps to the start of the track on scroll or swipe.

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="snap-content">
5 <span class="snap-tag">
6 01
7 </span>
8 <h3>
9 Mountain Peaks
10 </h3>
11 <p>
12 Explore the highest summits on Earth.
13 </p>
14 </div>
15 </div>
16 <div class="snap-slide" style="background:linear-gradient(135deg,#1a0533,#2d1b69)">
17 <div class="snap-content">
18 <span class="snap-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="snap-content">
31 <span class="snap-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="snap-content">
44 <span class="snap-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
Arrow Navigation

Previous/next arrows scroll the track by one viewport. Dots indicate the active slide and allow direct jumps. Boundary arrows disable automatically.

arrows
Live
untitled.html
HTML
1<div class="arrow-carousel">
2 <div class="arrow-track" id="arrow-track">
3 <div class="arrow-slide">
4 <div class="arrow-card">
5 <div class="arrow-visual" style="background:#1a1a2e">
6 <span>
7 01
8 </span>
9 </div>
10 <div class="arrow-body">
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="arrow-slide">
21 <div class="arrow-card">
22 <div class="arrow-visual" style="background:#16213e">
23 <span>
24 02
25 </span>
26 </div>
27 <div class="arrow-body">
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="arrow-slide">
38 <div class="arrow-card">
39 <div class="arrow-visual" style="background:#0f3460">
40 <span>
41 03
42 </span>
43 </div>
44 <div class="arrow-body">
45 <h4>
46 Project Gamma
47 </h4>
48 <p>
49 Machine learning pipeline.
50 </p>
51 </div>
52 </div>
53 </div>
54 <div class="arrow-slide">
55 <div class="arrow-card">
56 <div class="arrow-visual" style="background:#533483">
57 <span>
58 04
59 </span>
60 </div>
61 <div class="arrow-body">
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="arrow-btn prev" id="arrow-prev" aria-label="Previous slide">
73 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="16" height="16">
74 <polyline points="15 18 9 12 15 6"/>
75 </svg>
76 </button>
77 <button class="arrow-btn next" id="arrow-next" aria-label="Next slide">
78 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="16" height="16">
79 <polyline points="9 18 15 12 9 6"/>
80 </svg>
81 </button>
82 <div class="arrow-dots" id="arrow-dots">
83 <span class="arrow-dot active">
84 </span>
85 <span class="arrow-dot">
86 </span>
87 <span class="arrow-dot">
88 </span>
89 <span class="arrow-dot">
90 </span>
91 </div>
92</div>
preview
Auto-Play with Progress

An auto-advancing carousel that pauses on hover and resumes on leave. A progress bar visualizes the time remaining before the next slide.

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 g1">
5 <div class="auto-body">
6 <span class="auto-badge">
7 Featured
8 </span>
9 <h3>
10 Design Systems
11 </h3>
12 <p>
13 Build scalable component libraries with consistent tokens and patterns.
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 g2">
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.
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 g3">
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.
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">
59 <div class="auto-bar" id="auto-bar">
60 </div>
61 </div>
62 <div class="auto-controls">
63 <button class="auto-arrow" id="auto-prev" aria-label="Previous slide">
64 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="14" height="14">
65 <polyline points="15 18 9 12 15 6"/>
66 </svg>
67 </button>
68 <div class="auto-dots" id="auto-dots">
69 <span class="auto-dot active">
70 </span>
71 <span class="auto-dot">
72 </span>
73 <span class="auto-dot">
74 </span>
75 </div>
76 <button class="auto-arrow" id="auto-next" aria-label="Next slide">
77 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="14" height="14">
78 <polyline points="9 18 15 12 9 6"/>
79 </svg>
80 </button>
81 </div>
82</div>
preview
Multi-Item Carousel

Display multiple items per viewport with scroll snap. Each card uses flex: 0 0 calc(33.333% - 7px) for three visible items. Ideal for product grids, lesson lists, and card decks.

multi-item
Live
untitled.html
HTML
1<div class="multi-carousel">
2 <div class="multi-track">
3 <div class="multi-card">
4 <div class="multi-avatar" style="background:#1a1a2e">
5 JS
6 </div>
7 <div class="multi-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="multi-avatar" style="background:#16213e">
18 TS
19 </div>
20 <div class="multi-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="multi-avatar" style="background:#0f3460">
31 PY
32 </div>
33 <div class="multi-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="multi-avatar" style="background:#533483">
44 RS
45 </div>
46 <div class="multi-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="multi-avatar" style="background:#2d1810">
57 GO
58 </div>
59 <div class="multi-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="multi-avatar" style="background:#1a3a1a">
70 SW
71 </div>
72 <div class="multi-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 quotes and reviews. Slides crossfade every 5 seconds with manual dot navigation and author details.

testimonial
Live
untitled.html
HTML
1<div class="testi-carousel" id="testi-carousel">
2 <div class="testi-slide active" data-testi="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" data-testi="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" data-testi="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="testi-dot active" data-i="0" aria-label="Go to slide 1">
67 </button>
68 <button class="testi-dot" data-i="1" aria-label="Go to slide 2">
69 </button>
70 <button class="testi-dot" data-i="2" aria-label="Go to slide 3">
71 </button>
72 </div>
73</div>
preview
Full-Bleed Hero Slider

A wide hero-style slider with overlay text, bottom indicators, and full-bleed gradient backgrounds. Great for landing pages and feature highlights.

hero
Live
untitled.html
HTML
1<div class="hero-carousel" id="hero-carousel">
2 <div class="hero-track" id="hero-track">
3 <div class="hero-slide" style="background:linear-gradient(90deg,#0A0A0A 0%,#151515 60%,#1A1A2E 100%)">
4 <div class="hero-content">
5 <span class="hero-kicker">
6 v2.0 is live
7 </span>
8 <h2>
9 Ship faster with tokens
10 </h2>
11 <p>
12 Design tokens keep colors, spacing, and typography consistent across every platform.
13 </p>
14 <button class="hero-cta">
15 Read the docs
16 </button>
17 </div>
18 </div>
19 <div class="hero-slide" style="background:linear-gradient(90deg,#0A0A0A 0%,#151515 60%,#0c2340 100%)">
20 <div class="hero-content">
21 <span class="hero-kicker">
22 Performance
23 </span>
24 <h2>
25 Sub-millisecond edges
26 </h2>
27 <p>
28 Deploy globally and serve dynamic content from 200+ locations.
29 </p>
30 <button class="hero-cta">
31 View benchmarks
32 </button>
33 </div>
34 </div>
35 <div class="hero-slide" style="background:linear-gradient(90deg,#0A0A0A 0%,#151515 60%,#1a0533 100%)">
36 <div class="hero-content">
37 <span class="hero-kicker">
38 Security
39 </span>
40 <h2>
41 Zero-trust by default
42 </h2>
43 <p>
44 Authenticate every request with short-lived tokens and mTLS.
45 </p>
46 <button class="hero-cta">
47 Learn more
48 </button>
49 </div>
50 </div>
51 </div>
52 <div class="hero-dots" id="hero-dots">
53 <button class="active" aria-label="Slide 1">
54 </button>
55 <button aria-label="Slide 2">
56 </button>
57 <button aria-label="Slide 3">
58 </button>
59 </div>
60</div>
preview
Vertical Stack Carousel

A vertical carousel using scroll-snap-type: y mandatory. Useful for mobile stories, timeline steps, or stacked feature cards.

vertical
Live
untitled.html
HTML
1<div class="vert-carousel">
2 <div class="vert-track">
3 <div class="vert-slide">
4 <div class="vert-card">
5 <span class="vert-num">
6 01
7 </span>
8 <h4>
9 Discover
10 </h4>
11 <p>
12 Explore patterns and choose the right component for the job.
13 </p>
14 </div>
15 </div>
16 <div class="vert-slide">
17 <div class="vert-card">
18 <span class="vert-num">
19 02
20 </span>
21 <h4>
22 Build
23 </h4>
24 <p>
25 Implement the markup, styles, and behavior in your framework.
26 </p>
27 </div>
28 </div>
29 <div class="vert-slide">
30 <div class="vert-card">
31 <span class="vert-num">
32 03
33 </span>
34 <h4>
35 Test
36 </h4>
37 <p>
38 Verify keyboard navigation, screen reader output, and reduced motion.
39 </p>
40 </div>
41 </div>
42 <div class="vert-slide">
43 <div class="vert-card">
44 <span class="vert-num">
45 04
46 </span>
47 <h4>
48 Ship
49 </h4>
50 <p>
51 Deploy with confidence and monitor real user interactions.
52 </p>
53 </div>
54 </div>
55 </div>
56</div>
preview
HTML Structure

A semantic carousel structure uses a track container with scroll-snap-type, individual slides with scroll-snap-align, and labeled controls outside the track.

carousel-structure.html
HTML
1<section aria-roledescription="carousel" aria-label="Product screenshots">
2 <div class="carousel-track" style="scroll-snap-type: x mandatory">
3 <div class="carousel-slide" style="scroll-snap-align: start">
4 Slide 1
5 </div>
6 <div class="carousel-slide" style="scroll-snap-align: start">
7 Slide 2
8 </div>
9 </div>
10
11 <button type="button" class="prev" aria-label="Previous slide">
12 <svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24">
13 <polyline points="15 18 9 12 15 6" fill="none" stroke="currentColor" stroke-width="2"/>
14 </svg>
15 </button>
16 <button type="button" class="next" aria-label="Next slide">
17 <svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24">
18 <polyline points="9 18 15 12 9 6" fill="none" stroke="currentColor" stroke-width="2"/>
19 </svg>
20 </button>
21
22 <div class="indicators" role="tablist" aria-label="Slides">
23 <button role="tab" aria-selected="true" aria-label="Slide 1" class="active"></button>
24 <button role="tab" aria-selected="false" aria-label="Slide 2"></button>
25 </div>
26</section>
Best Practices

info

Use CSS scroll-snap-type for simple carousels — it provides native snap behavior, touch support, and keyboard scrolling without scripts.

warning

Auto-playing carousels must pause on hover and respect prefers-reduced-motion. Some users experience motion sickness from moving content.

best practice

Label every control with aria-label, use role="tablist" for dot indicators, and keep focus order logical.
  • Hide scrollbars with scrollbar-width: none and ::-webkit-scrollbar for a cleaner cross-browser look.
  • Use overflow: hidden on the outer 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 without JavaScript.
  • Support swipe on mobile through native touch scrolling instead of intercepting touch events.
  • For auto-play, use a 4–5 second interval and always provide manual controls.
  • Preload adjacent images and lazy-load off-screen slides to balance performance and perceived speed.
Accessibility

Carousels are one of the most accessibility-prone components. Follow these practical checks to make them usable for keyboard and screen reader users.

  • Wrap the carousel in a section with aria-roledescription="carousel" and a descriptive aria-label.
  • Use real <button> elements for controls, not clickable divs or spans.
  • Provide visible focus indicators on arrows, dots, and thumbnails.
  • Update aria-selected on dot indicators and aria-label on arrow buttons.
  • Pause auto-play when the carousel receives keyboard focus or hover, and never auto-advance critical content.
  • Respect prefers-reduced-motion by disabling animations and auto-play for users who request reduced motion.
  • Ensure all text and controls meet a 4.5:1 contrast ratio against the slide background.
  • Avoid keyboard traps — users must be able to tab past the carousel without getting stuck.

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.