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.
<cs-carouselpaginationnavigationmouse-draggingloop><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
Examples
Pagination
Use the pagination attribute to show the total number of slides and the current slide as a set of interactive dots.
<cs-carouselpagination><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
Navigation
Use the navigation attribute to show previous and next buttons.
<cs-carouselnavigation><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
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.
<cs-carouselloopnavigationpagination><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
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.
<cs-carouselautoplaylooppagination><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
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.
<cs-carouselclass="vertical"paginationorientation="vertical"><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel><style>.vertical{max-height: 400px;}.vertical::part(carousel){grid-template-areas:'slides slides pagination';}.vertical::part(pagination){flex-direction: column;}.vertical::part(navigation){transform:rotate(90deg);display: flex;}</style>
Aspect Ratio
Use the --aspect-ratio custom property to customize the size of the carousel’s viewport from the default value of 16/9.
1/13/216/9
<div><cs-carouselclass="aspect-ratio"navigationpaginationstyle="--aspect-ratio: 3/2;"><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel><cs-divider></cs-divider><divclass="cs-cluster"><cs-selectlabel="Aspect ratio"name="aspect"value="3/2"><cs-optionvalue="1/1">1/1</cs-option><cs-optionvalue="3/2">3/2</cs-option><cs-optionvalue="16/9">16/9</cs-option></cs-select></div></div><script>(()=>{const carousel = document.querySelector('cs-carousel.aspect-ratio');const aspectRatio = document.querySelector('cs-select[name="aspect"]');
aspectRatio.addEventListener('change',()=>{
carousel.style.setProperty('--aspect-ratio', aspectRatio.value);});})();</script>
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.
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.
<cs-carouselclass="scroll-hint"paginationstyle="--scroll-hint: 10%;"><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel>
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.
Enable mouse dragging
<divclass="mouse-dragging"><cs-carouselpagination><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel><cs-divider></cs-divider><cs-switch>Enable mouse dragging</cs-switch></div><script>const container = document.querySelector('.mouse-dragging');const carousel = container.querySelector('cs-carousel');const toggle = container.querySelector('cs-switch');
toggle.addEventListener('change',()=>{
carousel.toggleAttribute('mouse-dragging', toggle.checked);});</script>
Adding & Removing Slides
The content of the carousel can be changed by adding or removing carousel items. The carousel will update itself automatically.
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.
<cs-carouselclass="carousel-thumbnails"navigationloop><cs-carousel-item><imgalt="The sun shines on the mountains and trees (by Adam Kool on Unsplash)"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A river winding through an evergreen forest (by Luca Bravo on Unsplash)"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="The sun is setting over a lavender field (by Leonard Cotte on Unsplash)"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A field of grass with the sun setting in the background (by Sapan Patel on Unsplash)"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/></cs-carousel-item><cs-carousel-item><imgalt="A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></cs-carousel-item></cs-carousel><divclass="thumbnails"><divclass="scroller"><imgalt="Thumbnail by 1"class="image active"src="https://images.unsplash.com/photo-1426604966848-d7adac402bff?q=10"/><imgalt="Thumbnail by 2"class="image"src="https://images.unsplash.com/photo-1473448912268-2022ce9509d8?q=10"/><imgalt="Thumbnail by 3"class="image"src="https://images.unsplash.com/photo-1499002238440-d264edd596ec?q=10"/><imgalt="Thumbnail by 4"class="image"src="https://images.unsplash.com/photo-1475113548554-5a36f1f523d6?q=10"/><imgalt="Thumbnail by 5"class="image"src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?q=10"/></div></div><style>.carousel-thumbnails{--slide-aspect-ratio: 3 / 2;}.thumbnails{display: flex;justify-content: center;}.scroller{display: flex;gap:var(--cs-space-s);overflow-x: auto;scrollbar-width: none;scroll-behavior: smooth;scroll-padding:var(--cs-space-s);}.scroller::-webkit-scrollbar{display: none;}.image{width: 64px;height: 64px;object-fit: cover;opacity: 0.3;will-change: opacity;transition: 250ms opacity;cursor: pointer;}.image.active{opacity: 1;}</style><script>{const carousel = document.querySelector('.carousel-thumbnails');const scroller = document.querySelector('.scroller');const thumbnails = document.querySelectorAll('.image');
scroller.addEventListener('click',e=>{const target = e.target;if(target.matches('.image')){const index =[...thumbnails].indexOf(target);
carousel.goToSlide(index);}});
carousel.addEventListener('cs-slide-change',e=>{const slideIndex = e.detail.index;[...thumbnails].forEach((thumb, i)=>{
thumb.classList.toggle('active', i === slideIndex);if(i === slideIndex){
thumb.scrollIntoView({block:'nearest',});}});});}</script>
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.
When set, the slides will scroll automatically when the user is not interacting with them.
boolean
false
Yes
autoplayInterval
autoplay-interval
Specifies the amount of time, in milliseconds, between each automatic scroll.
number
3000
—
loop
loop
When set, allows the user to navigate the carousel in the same direction indefinitely.
boolean
false
Yes
mouseDragging
mouse-dragging
When set, it is possible to scroll through the slides by dragging them with the mouse.
boolean
false
Yes
navigation
navigation
When set, show the carousel's navigation.
boolean
false
Yes
orientation
orientation
Specifies the orientation in which the carousel will lay out.
'horizontal' | 'vertical'
'horizontal'
—
pagination
pagination
When set, show the carousel's pagination indicators.
boolean
false
Yes
slidesPerMove
slides-per-move
Specifies 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.
number
1
—
slidesPerPage
slides-per-page
Specifies how many slides should be shown at a given time.