Carousel
A component that allows users to cycle through a set of items, such as images or content, in a horizontal or vertical layout.
A component that allows users to cycle through a set of items, such as images or content, in a horizontal or vertical layout.
Basic usage example to quickly understand the functionality of the Carousel
component.
Demonstrates slide navigation, default layout, and interaction behaviors.
Install required dependencies before using the Carousel
.
These libraries handle the low-level carousel mechanics to ensure smooth performance and rich features.
Interactive configurator to customize the Carousel
component.
Explore options such as slide spacing, alignment, looping behavior, and other layout or navigation settings.
Demonstrates how to control the Carousel
manually using the provided hook API.
Gives you more flexibility and fine-grained control over slide behavior and carousel interactions.
Optional plugins to extend the functionality of your Carousel
.
Install additional features such as auto-scrolling and autoplay for richer experiences.
Example using the AutoScroll
plugin to enable continuous, smooth scrolling of slides without manual input.
Ideal for showcases, product sliders, or passive visual storytelling.
Example using the Autoplay
plugin to advance slides automatically at timed intervals.
Useful for banner sliders, announcement carousels, or interactive landing pages.
import { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselIndicators } from "@/ui/carousel";
export function CarouselDemo() {
return (
<Carousel>
<CarouselContent>
{datas.map((data, index) => (
<CarouselItem key={index}>{index}</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
<CarouselIndicators />
</Carousel>
);
}
"use client";
import { Carousel } from "@/ui/carousel";
export function CarouselDemo() {
return (
<Carousel>
<Carousel.Content>
{datas.map((data, index) => (
<Carousel.Item key={index}>{index}</Carousel.Item>
))}
</Carousel.Content>
<Carousel.Previous />
<Carousel.Next />
<Carousel.Indicators />
</Carousel>
);
}
import { Carousel } from "@/ui/carousel";
export function CarouselDemo() {
return (
<Carousel withControls withIndicators>
{datas.map((data, index) => (
<Carousel.Item key={index}>{index}</Carousel.Item>
))}
</Carousel>
);
}
type T = "root" | "content" | "item" | "previous" | "next" | "indicators" | "indicator";
Styles API | Type | Default | Annotation |
---|---|---|---|
unstyled? | Partial<Record<T, boolean>> | false | if true , default styles will be removed |
className? | string | undefined | pass to root component <div> |
classNames? | Partial<Record<T, string>> | undefined | |
style? | CSSProperties | undefined | pass to root component <div> |
styles? | Partial<Record<T, CSSProperties>> | undefined |
Props API | Type | Default | Annotation |
---|---|---|---|
dir? | "ltr" | "rtl" | ltr | |
orientation? | "horizontal" | "vertical" | horizontal | |
onPreviousSlide? | () => void | undefined | Called when previous itemr is shown |
onNextSlide? | () => void | undefined | Called when next item is shown |
onItemChange? | (index: number) => void | undefined | Called with slide index when slide changes |
setApi? | (api: CarouselApi) => void | undefined | Called with item index when item changes |
plugins? | EmblaPluginType[] | undefined | Called embla API as ref |
spacing? | number | string | 16 | Key of number to set gap between slides |
withControls? | boolean | false | Determines whether next/previous controls should be displayed |
withIndicators? | boolean | false | Determines whether indicators should be displayed |
opts? | CarouselOptions | undefined | Passing props EmblaOptionsType |
controlsOffset? | number | string | 0 | Controls position of the next and previous controls |
height? | CSSProperties["height"] | undefined | Slides container height , required for vertical orientation |
controlSize? | CSSProperties["width"] | undefined | Controls size of the next and previous controls |
withKeyboardEvents? | boolean | true | Determines whether arrow key should switch slides |
previousControlProps? | ComponentPropsWithoutRef<"button"> | undefined | Props passed down to previous control |
nextControlProps? | ComponentPropsWithoutRef<"button"> | undefined | Props passed down to next control |
icons? | { previous?: ReactNode; next?: React.ReactNode } | ChveronIcon | Icon of the previous or next as control |
Full working code example, including necessary markup and styles. You can copy and paste this code directly to start using the component immediately.