<cs-carousel>
ExperimentalMediaSince 0.1

Carousels display a series of content slides along a horizontal or vertical axis, one or more at a time. Users can navigate between slides with controls, pagination, or autoplay.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Examples

Pagination

Use the pagination attribute to show the total number of slides and the current slide as a set of interactive dots.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Use the navigation attribute to show previous and next buttons.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Loop

By default, the carousel will not advance beyond the first and last slides. You can change this behavior and force the carousel to “wrap” with the loop attribute.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Autoplay

The carousel will automatically advance when the autoplay attribute is used. To change how long a slide is shown before advancing, set autoplay-interval to the desired number of milliseconds. For best results, use the loop attribute when autoplay is enabled. Autoplay pauses while the user interacts with the carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Orientation

Setting the orientation attribute to vertical will render the carousel in a vertical layout. If the content of your slides vary in height, you will need to set an explicit height or max-height on the carousel using CSS.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Aspect Ratio

Use the --aspect-ratio custom property to customize the size of the carousel’s viewport from the default value of 16/9.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)
1/1 3/2 16/9

Multiple Slides per View

The slides-per-page attribute makes it possible to display multiple slides at a time. You can also use the slides-per-move attribute to advance more than one slide at a time, if desired.

Slide 1 Slide 2 Slide 3 Slide 4 Slide 5 Slide 6

Scroll Hint

Use the --scroll-hint custom property to add inline padding in horizontal carousels and block padding in vertical carousels. This will make the closest slides slightly visible, hinting that there are more items in the carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Mouse Dragging

The carousel uses scroll snap to position slides at various snap positions. This allows users to scroll through the slides very naturally, especially on touch devices. Unfortunately, desktop users won’t be able to click and drag with a mouse, which can feel unnatural. Adding the mouse-dragging attribute can help with this.

This example is best demonstrated using a mouse. Try clicking and dragging the slide to move it. Then toggle the switch and try again.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash) Enable mouse dragging

Adding & Removing Slides

The content of the carousel can be changed by adding or removing carousel items. The carousel will update itself automatically.

Slide 1 Slide 2 Slide 3
Add slide Remove slide

The carousel’s API makes it possible to extend and customize. This example syncs the active slide with a set of thumbnails, effectively creating a gallery-style carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)
Thumbnail by 1 Thumbnail by 2 Thumbnail by 3 Thumbnail by 4 Thumbnail by 5

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/carousel/carousel.js';
import './cornerstone/components/carousel/carousel.js';
import CsCarousel from '@cruglobal/cornerstone-components/react/carousel/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The carousel's main content, one or more <cs-carousel-item> elements.
next-iconOptional next icon to use instead of the default. Works best with <cs-icon>.
previous-iconOptional previous icon to use instead of the default. Works best with <cs-icon>.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
autoplayautoplayWhen set, the slides will scroll automatically when the user is not interacting with them.booleanfalseYes
autoplayIntervalautoplay-intervalSpecifies the amount of time, in milliseconds, between each automatic scroll.number3000
looploopWhen set, allows the user to navigate the carousel in the same direction indefinitely.booleanfalseYes
mouseDraggingmouse-draggingWhen set, it is possible to scroll through the slides by dragging them with the mouse.booleanfalseYes
navigationnavigationWhen set, show the carousel's navigation.booleanfalseYes
orientationorientationSpecifies the orientation in which the carousel will lay out.'horizontal' | 'vertical''horizontal'
paginationpaginationWhen set, show the carousel's pagination indicators.booleanfalseYes
slidesPerMoveslides-per-moveSpecifies the number of slides the carousel will advance when scrolling, useful when specifying a slides-per-page greater than one. It can't be higher than slides-per-page.number1
slidesPerPageslides-per-pageSpecifies how many slides should be shown at a given time.number1

Methods

Learn more about methods.

NameDescriptionArguments
addSlide()Adds a carousel item as the last real slide.slide: CsCarouselItem
goToSlide()Scrolls the carousel to the slide specified by index.index: number, behavior: ScrollBehavior
next()Move the carousel forward by slides-per-move slides.behavior: ScrollBehavior
previous()Move the carousel backward by slides-per-move slides.behavior: ScrollBehavior
removeSlide()Removes the real slide at the specified index.index: number

Events

Learn more about events.

NameDescription
cs-slide-changeEmitted when the active slide changes.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--aspect-ratioThe aspect ratio of each slide.16/9
--scroll-hintThe amount of padding to apply to the scroll area, allowing adjacent slides to become partially visible as a scroll hint.
--slide-gapThe space between each slide.var(--cs-space-m)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
carouselThe component's outer wrapper.::part(carousel)
navigationThe navigation wrapper.::part(navigation)
navigation-buttonThe navigation button.::part(navigation-button)
navigation-button-nextApplied to the next button.::part(navigation-button-next)
navigation-button-previousApplied to the previous button.::part(navigation-button-previous)
paginationThe pagination indicators wrapper.::part(pagination)
pagination-itemThe pagination indicator.::part(pagination-item)
pagination-item-activeApplied when the item is active.::part(pagination-item-active)
scroll-containerThe scroll container that wraps the slides.::part(scroll-container)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.

SSR

Learn more about Server-Side Rendering (SSR).

<cs-carousel> displays its first slide during SSR, but won't be interactive until it hydrates on the client.