Skip to main content

Starwind UI v1.12 is now available!

Carousel

Installation

Usage

General Notes

The Carousel component is built on top of Embla Carousel and provides a responsive, touch-enabled carousel with smooth animations. It supports both horizontal and vertical orientations, multiple items per view, and various configuration options.

The essential components are Carousel, CarouselContent, and CarouselItem. The CarouselPrevious and CarouselNext components provide navigation controls.

Multiple Items

Show multiple items at once by using responsive basis classes on carousel items.

Carousels can be oriented vertically by setting the orientation prop.

Enable infinite looping with the loop option.

Plugins

Extend carousel functionality with Embla Carousel plugins. First install the plugin package, then use manual initialization with the initCarousel function.

Info

You need to set autoInit={false} on the Carousel component, so that you can manually initialize it with your plugins and any additional options.

API Reference

The root carousel component that manages the carousel state and configuration.

PropTypeDefault
orientation"horizontal" | "vertical""horizontal"
optsEmblaOptionsType-
autoInitbooleantrue
idstring-
classstring-
<Carousel orientation="horizontal" opts={{ align: "start", loop: false }}>
<!-- Carousel content -->
</Carousel>

Additional Notes:

  • orientation: Controls the carousel scroll direction
  • opts: Embla Carousel options object for advanced configuration
  • autoInit: Whether to automatically initialize the carousel. Set to false when using plugins
  • id: Required when using manual initialization with plugins

CarouselContent

The scrollable content container that holds all carousel items.

PropTypeDefault
classstring-
<CarouselContent>
<!-- Carousel items -->
</CarouselContent>

CarouselItem

Individual carousel slide that can contain any content.

PropTypeDefault
classstring-
<CarouselItem class="md:basis-1/2 lg:basis-1/3">
<!-- Item content -->
</CarouselItem>

CarouselPrevious

Navigation button to go to the previous slide.

PropTypeDefault
variantButtonVariant"outline"
sizeButtonSize"icon"
classstring-
<CarouselPrevious variant="outline" size="icon" />

CarouselNext

Navigation button to go to the next slide.

PropTypeDefault
variantButtonVariant"outline"
sizeButtonSize"icon"
classstring-
<CarouselNext variant="outline" size="icon" />

Configuration Options

The opts prop accepts any Embla Carousel options. Common options include:

---
// Common configuration options
---
<Carousel opts={{
align: "start", // Alignment of slides
loop: false, // Enable infinite looping
skipSnaps: false, // Allow free scrolling
dragFree: false, // Enable drag free scrolling
containScroll: "trimSnaps", // Contain scroll behavior
slidesToScroll: 1, // Number of slides to scroll
startIndex: 0, // Starting slide index
}}>
<!-- Content -->
</Carousel>

Changelog

v1.0.1

  • Add named slot “icon” to CarouselNext and CarouselPrevious to enable easy icon swapping, and a default slot for the sr-only labels

v1.0.0

  • Initial release with starwind v1.9.0