Skip to content

Carousel with Captions

Bootstrap 5 hero carousel with glass captions, pill indicators, previous and next buttons, a pause control and gradient SVG slides.

Live preview

Open in new tab

Code

A Bootstrap 5 hero carousel with glass-style captions, pill indicators, round previous and next buttons and a pause/play control. The slides use CSS gradients and inline SVG landscapes instead of photos, so it loads instantly and works as a travel, product or campaign slider on landing pages.

How it works

The root section.ccx wraps a .carousel.slide.carousel-fade.ccx-carousel. Each carousel-item contains a .ccx-slide whose height comes from aspect-ratio: var(--ccx-ratio), a modifier class (.ccx-slide--sea, .ccx-slide--peak or .ccx-slide--dune) for its gradient, and an svg.ccx-art with simple shapes that scales with preserveAspectRatio="xMaxYMid slice". The .ccx-caption overrides Bootstrap's centered caption: it sits in the bottom-left corner, is left aligned and uses a translucent, blurred panel with a kicker, heading, short text and a .ccx-btn call to action. The .ccx-indicators become pills in the top-left corner, while the .ccx-control buttons and the .ccx-toggle pause button line up in the top-right corner so they never cover the caption.

Slide changes, indicators and swipe support come from Bootstrap's carousel plugin via data-bs-ride="carousel" and data-bs-interval="8000". The script runs on DOMContentLoaded, creates a bootstrap.Carousel instance for every .ccx-carousel and starts it paused when the visitor prefers reduced motion. Clicking .ccx-toggle recreates the instance with ride on or off, swaps the bi-pause-fill and bi-play-fill icons, updates the button label and sets aria-live to polite while paused.

Customization

  • --ccx-sea, --ccx-peak and --ccx-dune on .ccx in style.css: change the gradient behind each slide.
  • --ccx-ratio: controls the slide shape; it is 4 / 5 on phones, 4 / 3 from 576px and 16 / 7 from 992px.
  • --ccx-accent: recolors the kicker text and the .ccx-btn button.
  • --ccx-glass: makes the caption panel darker, lighter or tinted.
  • data-bs-interval="8000" on .ccx-carousel: sets the time per slide in milliseconds; the script reads the same value.
  • Replace an svg.ccx-art with an img from https://placehold.co/1200x600 or your own photo using object-fit: cover to show real images.
  • Remove carousel-fade from .ccx-carousel to slide horizontally instead of cross-fading.

Accessibility

The carousel has aria-roledescription="carousel" and a label, and each item is a role="group" with aria-roledescription="slide" and a position such as "1 of 3". Indicator buttons have descriptive labels and aria-current on the active slide. The previous and next buttons include visually hidden text, and the pause button meets WCAG 2.2.2 by letting users stop the auto-rotation. Autoplay is off under prefers-reduced-motion: reduce, and all buttons show a white focus outline on :focus-visible.

Usage notes

Requires Bootstrap 5 with its JS bundle (added automatically) and Bootstrap Icons. When adding a second carousel, give it a new id and update every data-bs-target.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Carousel with Captions – Bootstrap 5 carousels component screenshot
Carousel with Captions · Bootstrap 5 Carousels

More Carousels

Scroll-Snap Carousel – Pure CSS carousels preview

Scroll-Snap Carousel

Native CSS scroll-snap carousel with arrow buttons, synced pill dots and keyboard support, enhanced by a few lines of vanilla JavaScript.

Image Carousel with Thumbnails – Tailwind CSS carousels preview

Image Carousel with Thumbnails

Tailwind CSS image carousel with a clickable thumbnail strip, captions, swipe support, arrow-key navigation and optional looping.