Introducing PrimeReact v11-alpha 🎉Discover Now

Carousel

An unstyled, accessible carousel component with compound composition.

Build fully custom content sliders with complete control over layout, navigation, and indicators.

1
2
3
4
5
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Carousel with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, Content, Item, Prev, Next, Indicators, Indicator
  • CSS scroll-snap based navigation with configurable alignment and snap type
  • Mouse swipe gestures with automatic snap-to-closest behavior
  • IntersectionObserver-driven data-inview attribute on items
  • Horizontal and vertical orientation
  • Fractional slidesPerPage for partial item visibility

Usage#

import { Carousel } from 'primereact/carousel';
<Carousel.Root>
    <Carousel.Content>
        <Carousel.Item></Carousel.Item>
    </Carousel.Content>
    <Carousel.Indicators />
    <Carousel.Prev></Carousel.Prev>
    <Carousel.Next></Carousel.Next>
</Carousel.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Carousel.Root as="section">
    <Carousel.Content as="ul">
        <Carousel.Item as="li"></Carousel.Item>
    </Carousel.Content>
</Carousel.Root>

Default elements: Root=div, Content=div, Item=div, Prev=button, Next=button, Indicators=div, Indicator=button.

Render Function Children#

Indicators accepts a render function as children, providing access to the component instance. The instance exposes carousel (root instance with state.snapPoints).

<Carousel.Indicators>{(instance) => Array.from(instance.carousel?.state.snapPoints ?? []).map((_, i) => <Carousel.Indicator key={i} page={i}></Carousel.Indicator>)}</Carousel.Indicators>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

CarouselRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselRootInstance—
The instance to pass to the component.
ptSafeRecord<CarouselRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
autoSizebooleanfalse
Whether the carousel should auto size.
orientation"horizontal" | "vertical"'horizontal'
Orientation of the carousel.
align"center" | "start" | "end"'center'
Alignment of the carousel items.
loopbooleanfalse
Whether the carousel should loop.
snapType"mandatory" | "proximity"'mandatory'
Scroll snap type applied to the track.
spacingnumber16
Spacing between carousel items.
slidesPerPagenumber1
How many slides are visible per page. Supports fractions (e.g. 1.5).
pagenumberundefined
Index of the active slide.
slidenumberundefined
Index of the active slide.
defaultPagenumber0
Default index of the active slide.
onPageChange(event: useCarouselChangeEvent) => void—
Callback fired when the carousel's page changes.
onSlideChange(event: useCarouselChangeEvent) => void—
Callback fired when the active slide (by value) changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"
data-align"start", "center", or "end"
data-pageCurrent page index
data-swipingPresent when user is swiping
data-autosizePresent when autoSize is enabled

Defines passthrough(pt) options of Carousel component.

labeltypedescription
rootCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
contentCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
itemCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the item's DOM element.
prevCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the prev button's DOM element.
nextCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the next button's DOM element.
indicatorsCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the indicators' DOM element.
indicatorCarouselRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the indicator's DOM element.

CarouselContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselContentInstance—
The instance to pass to the component.
ptSafeRecord<CarouselContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"
data-align"start", "center", or "end"
data-pageCurrent page index
data-swipingPresent when user is swiping
data-autosizePresent when autoSize is enabled

CSS Custom Properties

The Content element sets three CSS custom properties on its style for use in item sizing and layout.

CSS VariableDescription
--slides-per-pageNumber of visible slides per page, derived from slidesPerPage.
--spacing-itemsGap between items in pixels, derived from spacing.
--scroll-snap-typeResolved scroll-snap-type value (e.g. x mandatory).

Defines passthrough(pt) options of CarouselContent component.

labeltypedescription
rootCarouselContentPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CarouselItem#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselItemInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselItemInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselItemInstance—
The instance to pass to the component.
ptSafeRecord<CarouselItemPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselItemInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-valueItem value identifier
data-inviewPresent when item is in viewport
data-orientation"horizontal" or "vertical"
data-align"start", "center", or "end"
data-autosizePresent when autoSize is enabled

Defines passthrough(pt) options of CarouselItem component.

labeltypedescription
rootCarouselItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CarouselPrev#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselPrevInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselPrevInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselPrevInstance—
The instance to pass to the component.
ptSafeRecord<CarouselPrevPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselPrevInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-disabledPresent when navigation is disabled
data-orientation"horizontal" or "vertical"

Defines passthrough(pt) options of CarouselPrev component.

labeltypedescription
rootCarouselPrevPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

CarouselNext#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselNextInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselNextInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselNextInstance—
The instance to pass to the component.
ptSafeRecord<CarouselNextPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselNextInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-disabledPresent when navigation is disabled
data-orientation"horizontal" or "vertical"

Defines passthrough(pt) options of CarouselNext component.

labeltypedescription
rootCarouselNextPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

CarouselIndicators#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselIndicatorsInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselIndicatorsInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselIndicatorsInstance—
The instance to pass to the component.
ptSafeRecord<CarouselIndicatorsPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselIndicatorsInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"

Defines passthrough(pt) options of CarouselIndicators component.

labeltypedescription
rootCarouselIndicatorsPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CarouselIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CarouselIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CarouselIndicatorInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCarouselIndicatorInstance—
The instance to pass to the component.
ptSafeRecord<CarouselIndicatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CarouselIndicatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
pagenumber—
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-activePresent when indicator is active
data-orientation"horizontal" or "vertical"

Defines passthrough(pt) options of CarouselIndicator component.

labeltypedescription
rootCarouselIndicatorPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Carousel uses semantic HTML with button elements for navigation controls and indicators. Navigation buttons should include descriptive labels via aria-label. The current page can be announced with an aria-live region.

<Carousel.Root>
    <Carousel.Content aria-label="Image carousel">
        <Carousel.Item></Carousel.Item>
    </Carousel.Content>
    <Carousel.Prev aria-label="Previous slide"></Carousel.Prev>
    <Carousel.Next aria-label="Next slide"></Carousel.Next>
</Carousel.Root>

Keyboard Support#

KeyFunction
tabMoves focus between navigation buttons and indicators.
enter / spaceActivates the focused button or indicator.