Carousel
A set of slides that lets users move through content one slide at a time.
A carousel shows one slide of a set at a time and keeps the others out of view. Users move through the set by dragging the slides, with the previous and next buttons, or with the left and right arrow keys while focus is inside the carousel. On the first and the last slide, the button that leads no further is disabled.
Usage
Examples
Loop
Some sets have no natural first or last slide, such as the promotions running in a store this week. With loop set to true in opts, the carousel continues from the last slide to the first and back again, so users keep browsing in either direction and the buttons no longer stop at either end.
With Slide Counter
While users move through a set one slide at a time, they easily lose track of how far they have come and how much remains. Through setApi the application gains access to the carousel, so it can show the position of the current slide and update it with every move, whether users drag, press a button or use the arrow keys.
Photo 1 of 3
API Reference
Carousel
| Prop | opts |
|---|---|
| Type | EmblaOptionsType |
| Default | – |
| Description | Sets the options of Embla Carousel, the library that moves the slides, such as loop, align and startIndex. The carousel derives axis from orientation, so an axis set here has no effect. |
| Prop | plugins |
|---|---|
| Type | EmblaPluginType[] |
| Default | – |
| Description | Passes plugins to Embla Carousel. Each plugin adds a behavior that the library doesn't include itself. |
| Prop | orientation |
|---|---|
| Type | "horizontal" | "vertical" |
| Default | "horizontal" |
| Description | Sets the axis along which the slides move. A horizontal carousel places the previous and next buttons to the left and right of the slides, a vertical one places them above and below. |
| Prop | setApi |
|---|---|
| Type | (api: CarouselApi) => void |
| Default | – |
| Description | Runs when the carousel has initialized and receives the Embla Carousel API. With the API, code reads the selected slide, scrolls the carousel and subscribes to events such as select. Pass a function with a stable identity, such as a state setter, because the carousel calls it again whenever the function changes. |
CarouselContent
CarouselContent holds the slides and clips the ones that are out of view. It renders a div inside a clipping div, passes native attributes to the inner one, and has no props of its own.
CarouselItem
CarouselItem holds one slide. It renders a div that assistive technology announces as a slide, and it has no props of its own.
CarouselPrevious
| Prop | variant |
|---|---|
| Type | "default" | "outline" | "secondary" | "ghost" | "destructive" | "link" |
| Default | "outline" |
| Description | Controls the visual emphasis and semantic role of the previous button. |
| Prop | size |
|---|---|
| Type | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" |
| Default | "icon-sm" |
| Description | Controls the dimensions and spacing of the previous button. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the previous button with another component. |
| Prop | nativeButton |
|---|---|
| Type | boolean |
| Default | true |
| Description | Declares whether the rendered element is a native button. Set it to false when render returns a different element. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | – |
| Description | Overrides the disabled state of the previous button. Without it, the carousel disables the button while there is no previous slide to scroll to. |
| Prop | focusableWhenDisabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Keeps the previous button focusable while it is disabled. |
CarouselNext
| Prop | variant |
|---|---|
| Type | "default" | "outline" | "secondary" | "ghost" | "destructive" | "link" |
| Default | "outline" |
| Description | Controls the visual emphasis and semantic role of the next button. |
| Prop | size |
|---|---|
| Type | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" |
| Default | "icon-sm" |
| Description | Controls the dimensions and spacing of the next button. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the next button with another component. |
| Prop | nativeButton |
|---|---|
| Type | boolean |
| Default | true |
| Description | Declares whether the rendered element is a native button. Set it to false when render returns a different element. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | – |
| Description | Overrides the disabled state of the next button. Without it, the carousel disables the button while there is no next slide to scroll to. |
| Prop | focusableWhenDisabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Keeps the next button focusable while it is disabled. |