Overview
The Carousel component provides a fully-featured image and content slider with support for automatic sliding, navigation buttons, indicators, captions, and custom rendering. It’s built with composition in mind and offers fine-grained control over behavior and appearance.Use Cases
- Image galleries and slideshows
- Product showcases and feature highlights
- Testimonial sliders
- Hero sections with rotating content
- Portfolio presentations
Installation
The Carousel component is included with the UI package:Basic Usage
Component Parts
Carousel.Root
The root container that manages carousel state and behavior.images- Array of image URLs or objects with image data (required)hasAutoSlide- Enable automatic sliding (default:false)autoSlideInterval- Interval in milliseconds for auto-slide (default:3000)shouldPauseOnHover- Pause auto-slide on hover (default:false)onSlideBtnClick- Callback when navigation buttons are clickedclassNames- Custom classes forbaseandscrollContaineras- Change rendered element (default:"div")
Carousel.ItemList
Container for carousel items with slide transition animations.children- Render function receiving{ image, index, array }or static contenteach- Optional array to override images from RootclassName- Custom CSS classes
Carousel.Item
Individual carousel item wrapper.Carousel.Controls
Navigation controls container with previous/next buttons.classNames- Custom classes for controls, icon container, and default iconicon- Custom navigation icons (see Icon Patterns below)
Carousel.Button
Individual navigation button (used internally by Controls).Carousel.IndicatorList
Container for slide indicators.Carousel.Indicator
Individual slide indicator dot/button.Carousel.Caption
Overlay caption for carousel items.Examples
Auto-Playing Carousel
Carousel with Captions
Custom Navigation Icons
Single Icon Pattern
You can also use a single icon that rotates for the next button:Navigation Patterns
The carousel supports flexible icon configuration:- Separate Icons
- Single Icon (Prev)
- Single Icon (Next)
Styling
All Carousel parts include data attributes for styling:Custom Styling Example
Accessibility
- Navigation buttons include
type="button"and proper ARIA labels - Indicators are clickable buttons that navigate to specific slides
- Keyboard navigation supported through button elements
- Auto-slide pauses on hover when
shouldPauseOnHoveris enabled
The carousel uses CSS transforms for smooth transitions between slides.