Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Carousel

Browse a collection with Material carousel layouts. Swipe, scroll, or use the arrow keys.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A carousel shows a collection of items that scroll on and off the screen, changing size as they move and settling into place: artwork, photos, featured entries, to browse rather than read in full. M3 has five layouts: multi-browse, uncontained, hero, center-aligned hero and full-screen.

Usage

The carousel fills the height it is given, and has none of its own: set one on it or on its container. change fires with the value of the item that settles into the focal position: its index, as getValue() returns it.

Vanilla
import { createCarousel } from 'material';

const carousel = createCarousel({
  ariaLabel: 'Places to explore',
  slides: [
    {
      image: '/assets/playground/landscape-1.svg',
      alt: 'Hills under a pale sky',
      title: 'Highlands',
    },
    {
      image: '/assets/playground/landscape-2.svg',
      alt: 'Cliffs over the sea',
      title: 'Coast',
    },
    {
      image: '/assets/playground/landscape-3.svg',
      alt: 'Dunes at noon',
      title: 'Desert',
    },
  ],
});
carousel.element.style.height = '320px';
carousel.on('change', ({ value }) => showSlide(value));
document.body.append(carousel.element);
Web Components
<m-carousel aria-label="Places to explore" style="height: 320px">
  <m-carousel-item src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky">Highlands</m-carousel-item>
  <m-carousel-item src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea">Coast</m-carousel-item>
  <m-carousel-item src="/assets/playground/landscape-3.svg" alt="Dunes at noon">Desert</m-carousel-item>
</m-carousel>

<script type="module">
  const carousel = document.querySelector('m-carousel');
  carousel.addEventListener('change', (event) => showSlide(event.detail.value));
</script>
React
import { Carousel, CarouselItem } from 'material/react';
import { showSlide } from './app';

export function Example() {
  return (
    <Carousel onChange={(event) => showSlide(event.detail.value)} ariaLabel="Places to explore" style={{ height: '320px' }}>
      <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky">Highlands</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea">Coast</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon">Desert</CarouselItem>
    </Carousel>
  );
}
Vue
<script setup lang="ts">
import { MCarousel, MCarouselItem } from 'material/vue';
import { showSlide } from './app';
</script>

<template>
  <MCarousel @change="showSlide($event.detail.value)" aria-label="Places to explore" style="height: 320px">
    <MCarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky">Highlands</MCarouselItem>
    <MCarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea">Coast</MCarouselItem>
    <MCarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon">Desert</MCarouselItem>
  </MCarousel>
</template>
Svelte
<script lang="ts">
  import { Carousel, CarouselItem } from 'material/svelte';
  import { showSlide } from './app';
</script>

<Carousel onchange={(event) => showSlide(event.detail.value)} ariaLabel="Places to explore" style="height: 320px">
  <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky">Highlands</CarouselItem>
  <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea">Coast</CarouselItem>
  <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon">Desert</CarouselItem>
</Carousel>
SolidJS
import { Carousel, CarouselItem } from 'material/solid';
import { showSlide } from './app';

export function Example() {
  return (
    <Carousel onChange={(event) => showSlide(event.detail.value)} ariaLabel="Places to explore" style="height: 320px">
      <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky">Highlands</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea">Coast</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon">Desert</CarouselItem>
    </Carousel>
  );
}

Examples

Hero, with a call to action

variant picks the layout. hero shows one large item and a glimpse of the next; hero-center centers it between two small ones. itemWidth is a large item's preferred width, and in the hero layouts its maximum. A slide's buttonText and buttonUrl add a link.

Vanilla
import { createCarousel } from 'material';

const carousel = createCarousel({
  variant: 'hero',
  itemWidth: 480,
  ariaLabel: 'Collections',
  slides: [
    {
      image: '/assets/playground/landscape-4.svg',
      alt: 'A forest path',
      title: 'Spring collection',
      description: 'Out now',
      buttonText: 'Browse',
      buttonUrl: '/collections/spring',
    },
    {
      image: '/assets/playground/landscape-5.svg',
      alt: 'A lake at dawn',
      title: 'Lakeside',
    },
  ],
});
carousel.element.style.height = '320px';
document.body.append(carousel.element);
Web Components
<m-carousel variant="hero" item-width="480" aria-label="Collections" style="height: 320px">
  <m-carousel-item src="/assets/playground/landscape-4.svg" alt="A forest path" description="Out now" button-text="Browse" button-url="/collections/spring">Spring collection</m-carousel-item>
  <m-carousel-item src="/assets/playground/landscape-5.svg" alt="A lake at dawn">Lakeside</m-carousel-item>
</m-carousel>
React
import { Carousel, CarouselItem } from 'material/react';

export function Example() {
  return (
    <Carousel variant="hero" itemWidth={480} ariaLabel="Collections" style={{ height: '320px' }}>
      <CarouselItem src="/assets/playground/landscape-4.svg" alt="A forest path" description="Out now" buttonText="Browse" buttonUrl="/collections/spring">Spring collection</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-5.svg" alt="A lake at dawn">Lakeside</CarouselItem>
    </Carousel>
  );
}
Vue
<script setup lang="ts">
import { MCarousel, MCarouselItem } from 'material/vue';
</script>

<template>
  <MCarousel variant="hero" :item-width="480" aria-label="Collections" style="height: 320px">
    <MCarouselItem src="/assets/playground/landscape-4.svg" alt="A forest path" description="Out now" button-text="Browse" button-url="/collections/spring">Spring collection</MCarouselItem>
    <MCarouselItem src="/assets/playground/landscape-5.svg" alt="A lake at dawn">Lakeside</MCarouselItem>
  </MCarousel>
</template>
Svelte
<script lang="ts">
  import { Carousel, CarouselItem } from 'material/svelte';
</script>

<Carousel variant="hero" itemWidth={480} ariaLabel="Collections" style="height: 320px">
  <CarouselItem src="/assets/playground/landscape-4.svg" alt="A forest path" description="Out now" buttonText="Browse" buttonUrl="/collections/spring">Spring collection</CarouselItem>
  <CarouselItem src="/assets/playground/landscape-5.svg" alt="A lake at dawn">Lakeside</CarouselItem>
</Carousel>
SolidJS
import { Carousel, CarouselItem } from 'material/solid';

export function Example() {
  return (
    <Carousel variant="hero" itemWidth={480} ariaLabel="Collections" style="height: 320px">
      <CarouselItem src="/assets/playground/landscape-4.svg" alt="A forest path" description="Out now" buttonText="Browse" buttonUrl="/collections/spring">Spring collection</CarouselItem>
      <CarouselItem src="/assets/playground/landscape-5.svg" alt="A lake at dawn">Lakeside</CarouselItem>
    </Carousel>
  );
}

Uncontained

Items keep one size and run off the trailing edge, and the list scrolls freely, without settling on an item.

Vanilla
import { createCarousel } from 'material';

const carousel = createCarousel({
  variant: 'uncontained',
  itemWidth: 240,
  ariaLabel: 'Recent photos',
  slides: [
    {
      image: '/assets/playground/landscape-1.svg',
      alt: 'Hills under a pale sky',
    },
    {
      image: '/assets/playground/landscape-2.svg',
      alt: 'Cliffs over the sea',
    },
    {
      image: '/assets/playground/landscape-3.svg',
      alt: 'Dunes at noon',
    },
  ],
});
carousel.element.style.height = '320px';
document.body.append(carousel.element);
Web Components
<m-carousel variant="uncontained" item-width="240" aria-label="Recent photos" style="height: 320px">
  <m-carousel-item src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky"></m-carousel-item>
  <m-carousel-item src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea"></m-carousel-item>
  <m-carousel-item src="/assets/playground/landscape-3.svg" alt="Dunes at noon"></m-carousel-item>
</m-carousel>
React
import { Carousel, CarouselItem } from 'material/react';

export function Example() {
  return (
    <Carousel variant="uncontained" itemWidth={240} ariaLabel="Recent photos" style={{ height: '320px' }}>
      <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky" />
      <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea" />
      <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon" />
    </Carousel>
  );
}
Vue
<script setup lang="ts">
import { MCarousel, MCarouselItem } from 'material/vue';
</script>

<template>
  <MCarousel variant="uncontained" :item-width="240" aria-label="Recent photos" style="height: 320px">
    <MCarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky" />
    <MCarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea" />
    <MCarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon" />
  </MCarousel>
</template>
Svelte
<script lang="ts">
  import { Carousel, CarouselItem } from 'material/svelte';
</script>

<Carousel variant="uncontained" itemWidth={240} ariaLabel="Recent photos" style="height: 320px">
  <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky" />
  <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea" />
  <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon" />
</Carousel>
SolidJS
import { Carousel, CarouselItem } from 'material/solid';

export function Example() {
  return (
    <Carousel variant="uncontained" itemWidth={240} ariaLabel="Recent photos" style="height: 320px">
      <CarouselItem src="/assets/playground/landscape-1.svg" alt="Hills under a pale sky" />
      <CarouselItem src="/assets/playground/landscape-2.svg" alt="Cliffs over the sea" />
      <CarouselItem src="/assets/playground/landscape-3.svg" alt="Dunes at noon" />
    </Carousel>
  );
}

multi-browse, the default, shows at least one large, one medium and one small item, and more large ones as the container grows. full-screen shows one edge-to-edge item at a time and scrolls vertically. The layouts follow Compose's keylines: each item's size and place come from the scroll offset. In the factory, a slide's content (an element or markup) replaces the image and text, and next(), prev() and goTo(index) move the carousel.

A slide's image may state the intrinsic size of the file with width and height, in pixels. The browser reserves a box of that ratio before the image arrives, so the carousel does not jump as files load. loading chooses when the file is fetched: the slide that opens the carousel is "eager", every later one "lazy", and a slide can override either. decoding passes the hint of the same name to the image. All four are optional.

API

Options

variant

The layout

Type'multi-browse' | 'uncontained' | 'hero' | 'hero-center' | 'full-screen'
Default'multi-browse'
slides

The items

TypeCarouselSlide[]
Default[]
itemWidth

A large item's width in pixels; a maximum in the hero layouts

Typenumber
Default280
gap

Space between items in pixels

Typenumber
Default8, 16 for full-screen
padding

Space between the container's edges and the items

Typenumber
Default16, 0 for full-screen
cornerRadius

The items' corner radius in pixels

Typenumber
Default28
snap

Whether scrolling settles on an item

Typeboolean
Defaulttrue, false for uncontained
initialSlide

The item shown first

Typenumber
Default0
minSmallItemWidth / maxSmallItemWidth

A small item's width range

Typenumber
Default40 / 56
ariaLabel

The carousel's accessible name

Typestring
Default'Carousel'
class

Additional CSS classes

Typestring
Defaultundefined
prefix

Prefix for CSS class names

Typestring
Default'mtrl'

Slides

image

Image URL

Typestring
alt

The image's alt text; title without it, and '' for a decorative image

Typestring
width / height

The image's intrinsic size in pixels

Typenumber
loading

'eager' for the first slide, 'lazy' for every other

Type'eager' | 'lazy'
decoding

Passed to the <img>

Type'sync' | 'async' | 'auto'
title / description

Text over the image

Typestring
buttonText / buttonUrl

A call-to-action link

Typestring
content

The app's own content, instead of the image and text

TypeHTMLElement | string

Methods

next() / prev()

The next or previous item, stopping at the ends

ReturnsCarouselComponent
goTo(index)

Scrolls to an item, smoothly unless reduced motion is on

ReturnsCarouselComponent
getCurrentSlide()

The item in the focal position

Returnsnumber
getVariant()

The layout

ReturnsCarouselVariant
addSlide(slide, index?) / removeSlide(index)

Adds or removes an item

ReturnsCarouselComponent
slides.updateSlide(index, slide)

Replaces an item's content in place

ReturnsSlidesAPI
slides.getSlide(index) / slides.getCount() / slides.getElements()

Reads the items

ReturnsCarouselSlide | null / number / HTMLElement[]
on(event, handler) / off(event, handler)

Events

ReturnsCarouselComponent
addClass(...classes)

Adds classes to the root

ReturnsCarouselComponent
destroy()

Removes the carousel, its observer and its listeners

Returnsvoid

Events

change

Another item settled into the focal position; value is its index. A goTo() reports its destination only

Payload{ value }

The web component's change carries { value } too.

Styling

The component writes --mtrl-carousel-corner on the root, the corner radius, and --mtrl-carousel-fade on each item, from 1 when large to 0 when small, which the text overlay fades with. It also writes each item's transform and clip-path as it scrolls: don't set them from CSS. The root also carries the layout as a modifier, such as mtrl-carousel--hero, which the stylesheet does not style.

.mtrl-carousel { }
.mtrl-carousel--vertical, .mtrl-carousel--snap { }
.mtrl-carousel__scroller, .mtrl-carousel__track, .mtrl-carousel__item, .mtrl-carousel__image { }
.mtrl-carousel__content, .mtrl-carousel__title, .mtrl-carousel__description, .mtrl-carousel__button { }

Measurements

From Compose's CarouselDefaults:

Attribute Value
Space between items 8dp; 16dp full screen
Container padding 16dp
Item corner 28dp
Small item 40 to 56dp wide
Anchor size 10dp outside the container