Carousel
An interactive slideshow component for cycling through elements.
Anatomy
<Carousel.Root>
<Carousel.Control>
<Carousel.PrevTrigger />
<Carousel.NextTrigger />
</Carousel.Control>
<Carousel.ItemGroup>
<Carousel.Item />
</Carousel.ItemGroup>
<Carousel.IndicatorGroup>
<Carousel.Indicator />
</Carousel.IndicatorGroup>
</Carousel.Root>
Examples
Controlled
Use page and onPageChange to control the current page.
Root Provider
Use RootProvider with the useCarousel hook to access the state and methods from outside the component.
Autoplay
Set autoplay and loop on Carousel.Root to play the slides automatically.
Pause on Hover
Pause on hover isn't built in. Call play() and pause() from Carousel.Context to add it.
Thumbnail Indicators
Render an image thumbnail inside each Carousel.Indicator in place of the default dots.
Vertical
Set orientation="vertical" on Carousel.Root to scroll vertically.
Dynamic
Store slides in state and keep the page in sync. Pass page and onPageChange to Carousel.Root, and update
slideCount when slides are added or removed.
Scroll to Slide
Call api.scrollToIndex(index) from Carousel.Context to jump to a specific slide.
Slides Per Page
Set slidesPerPage on Carousel.Root to show several slides at once. Render indicators from api.pageSnapPoints so
there is one per page, not per slide. Use spacing to set the gap.
Spacing
Set spacing on Carousel.Root to control the gap between slides. Combine it with slidesPerPage to show partial
previews of adjacent slides.
Variable Sizes
Set autoSize on Carousel.Root so each Carousel.Item can define its own width. Use snapAlign on an item to
control where it snaps into view.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
count | numberThe total number of slides. Useful for SSR to render the initial snap points. | |
allowMouseDrag | false | booleanWhether to allow scrolling via dragging with mouse |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
autoPlay | false | boolean | { delay: number }Whether to scroll automatically. The default delay is 4000ms. |
autoSize | false | booleanWhether to enable variable width slides. |
defaultPage | 0 | numberThe initial page to scroll to when rendered. Use when you don't need to control the page of the carousel. |
ids | ElementIdsThe ids of the elements in the carousel. Useful for composition. | |
inViewThreshold | 0.6 | number | number[]The threshold for determining if an item is in view. |
itemSpacing | stringDefines the extra space added around the scrollable area, enabling nearby items to remain partially in view. | |
loop | false | booleanWhether the carousel should loop around. |
onAutoplayStatusChange | (details: AutoplayStatusDetails) => voidFunction called when the autoplay status changes. | |
onDragStatusChange | (details: DragStatusDetails) => voidFunction called when the drag status changes. | |
onPageChange | (details: PageChangeDetails) => voidFunction called when the page changes. | |
orientation | 'horizontal' | 'horizontal' | 'vertical'The orientation of the element. |
page | numberThe controlled page of the carousel. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
slidesPerMove | 'auto' | number | 'auto'The number of slides to scroll at a time. When set to `auto`, the number of slides to scroll is determined by the `slidesPerPage` property. |
slidesPerPage | 1 | numberThe number of slides to show at a time. |
snapType | 'mandatory' | 'proximity' | 'mandatory'The snap type of the item. |
spacing | '0px' | stringThe amount of space between items. |
translations | IntlTranslationsThe localized messages to use. |
| Attribute | Description |
|---|---|
[data-carousel-root] | <uid> |
[data-orientation] | The orientation of the carousel |
| CSS Variable | Description |
|---|---|
--slides-per-page | The number of slides visible per page |
--slide-spacing | The spacing between slides |
--slide-item-size | The calculated size of each slide item |
AutoplayIndicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
fallback | string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>The fallback content to render when autoplay is paused. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
AutoplayTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-autoplay-trigger] | <uid> |
[data-orientation] | The orientation of the autoplaytrigger |
[data-pressed] | Present when pressed |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-control] | <uid> |
[data-orientation] | The orientation of the control |
IndicatorGroup
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-indicator-group] | <uid> |
[data-orientation] | The orientation of the indicatorgroup |
Indicator
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
index | numberThe index of the indicator. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
readOnly | false | booleanWhether the indicator is read only. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<CarouselIndicatorState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-indicator] | <uid> |
[data-orientation] | The orientation of the indicator |
[data-index] | The index of the item |
[data-readonly] | Present when read-only |
[data-current] | Present when current |
ItemGroup
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-item-group] | <uid> |
[data-orientation] | The orientation of the item |
[data-dragging] | Present when in the dragging state |
Item
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
index | numberThe index of the item. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<CarouselItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
snapAlign | 'start' | 'center' | 'start' | 'end'The snap alignment of the item. |
| Attribute | Description |
|---|---|
[data-carousel-item] | <uid> |
[data-index] | The index of the item |
[data-inview] | Present when in viewport |
[data-orientation] | The orientation of the item |
NextTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-carousel-next-trigger] | <uid> |
[data-orientation] | The orientation of the nexttrigger |
PrevTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
ProgressText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseCarouselReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Context
API
| Property | Type |
|---|---|
page | numberThe current index of the carousel |
pageSnapPoints | number[]The current snap points of the carousel |
isPlaying | booleanWhether the carousel is auto playing |
isDragging | booleanWhether the carousel is being dragged. This only works when `draggable` is true. |
canScrollNext | booleanWhether the carousel is can scroll to the next view |
canScrollPrevious | booleanWhether the carousel is can scroll to the previous view |
scrollToIndex | (index: number, instant?: boolean) => voidFunction to scroll to a specific item index |
scrollTo | (page: number, instant?: boolean) => voidFunction to scroll to a specific page |
scrollNext | (instant?: boolean) => voidFunction to scroll to the next page |
scrollPrevious | (instant?: boolean) => voidFunction to scroll to the previous page |
getProgress | () => numberReturns the current scroll progress as a percentage |
getProgressText | () => stringReturns the progress text |
play | VoidFunctionFunction to start/resume autoplay |
pause | VoidFunctionFunction to pause autoplay |
isInView | (index: number) => booleanWhether the item is in view |
refresh | VoidFunctionFunction to re-compute the snap points and clamp the page |
getItemState | (props: ItemProps) => ItemStateReturns the state of a carousel item |
getIndicatorState | (props: IndicatorProps) => IndicatorStateReturns the state of a carousel indicator |
Accessibility
Complies with the Carousel WAI-ARIA design pattern.