Carousel
ExpressiveA scrollable row of items that resize along keylines: multi-browse, uncontained, multi-aspect, hero or full-screen.
import { Carousel } from '@windmorph/react';Props
Carousel 25 props
The items, e.g. images; each fills its slot and is clipped to its keyline. In multi-browse and hero carousels each item (
data-slot="item") carriesdata-size(large,mediumorsmall; every itemlargeunder reduced motion) and--m3-carousel-item-openness, from 0 at its smallest to 1 at its largest, so words over it can fade as it shrinks.The root element's id.
varianttype"multi-browse" | "uncontained" | "multi-aspect" | "hero" | "full-screen"default"multi-browse"multi-browseshows large, medium and small items;uncontainedshows items of one size that flow past the end edge, never masked or resized;multi-aspectis uncontained with items of their own widths (9:16 to 16:9);heroshows one large item with small ones beside it;full-screenshows one edge-to-edge item at a time.The direction the items scroll in.
Preferred size of the large items along the carousel (multi-browse, hero). Hero defaults to the whole carousel.
Size of the items along the carousel (uncontained).
Space between items, px.
Centre the large hero item between small ones.
Minimum size of the small items.
Maximum size of the small items.
contentPaddingtypePartial<CarouselContentPadding>default{ start: 16, end: 16, cross: 8 } (uncontained and multi-aspect: no end padding; full-screen: none)Padding around the items. Items scroll over the start and end padding.
Snap uncontained and multi-aspect carousels to their items. Multi-browse, hero and full-screen carousels always snap.
Makes an item a link to the address it returns (
undefinedfor one that isn't): a real link, so aRouterProviderroutes it, and a modifier or the context menu opens it in a new tab, as any link. The item's press area is the link, and the link is the item's tab stop: Enter follows it, andonActionisn't called for it. The item's content names the link, so an image needs a non-emptyalt(or words beside it); a link item must not hold buttons or other links. A disabled item (disabledIndexes) keeps its name and tab stop but no address.Where an item's link opens (
_blankfor a new tab), withitemHref.An item's link's relationship to the page (
nofollow,noopener), withitemHref.Indexes of items that can't be activated.
Ref to the root
<div>element.
Events
Called when an item is pressed, or activated with Enter or Space. Items then show hover, focus and pressed states. Not called for an item that is a link (
itemHref).Called when another item takes the focal (large) place, once scrolling has settled (150ms without a scroll): the item an app's words or controls describe. Multi-browse and hero carousels. The item that is focal when the carousel first lays out is the starting point, not a change, so it isn't reported. Each item's size is on the item itself (
children).
Text
Words the carousel announces, for localisation. A
LabelsProvidersets them for the whole app.labels.slidetype(position: string, count: string) => stringdefault (position, count) =>${position} of ${count}Each item's name: its position (from 1) and the number of items, as formatted text.
What the carousel is, read before its name (
aria-roledescription).What each item is, read before its name (
aria-roledescription).
Accessible name when there's no visible title.
One of
aria-labeloraria-labelledbyis required.The id of the visible title that names the carousel.
One of
aria-labeloraria-labelledbyis required.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
classNames.rootis merged withclassName.The outer element, which holds the carousel's name.
The scrolling track that holds the items.
Each item's slot, sized and placed on its keyline.
The masked layer of each item (corners, clipping).
The state layer painted over an item that can be activated.
The link of an item that is one (
itemHref), holding its press area and its mask.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints |
|---|---|---|
--md-comp-carousel-item-container-shape | var(--md-sys-shape-corner-extra-large) | Each item's corners (not the full-screen variant's, which are square). |
Spec status
Built to the M3 Expressive carousel spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Multi-browse | Built | Variant · Multibrowse |
| Uncontained | Built | Variant · Variants |
| Uncontained multi-aspect ratio | Built | Variant · Layouts |
| Hero | Built | Variant · Hero |
| Center-aligned hero | Built | Variant · Variants |
| Full-screen | Built | Variant · Layouts |
| Items that open something | Built | Use case · Actions |
| Vertical carousels | Extension | orientation="vertical" lays out any variant in a column; the spec shows only full-screen carousels vertically. |
| Parallax | Not built | There's no parallax helper; each item's visible size is exposed as --m3-carousel-item-size to build one. |
Multi-browse
BuiltVariant · Multibrowse
Uncontained
BuiltVariant · Variants
Uncontained multi-aspect ratio
BuiltVariant · Layouts
Hero
BuiltVariant · Hero
Center-aligned hero
BuiltVariant · Variants
Full-screen
BuiltVariant · Layouts
Items that open something
BuiltUse case · Actions
Vertical carousels
Extensionorientation="vertical"lays out any variant in a column; the spec shows only full-screen carousels vertically.Parallax
Not builtThere's no parallax helper; each item's visible size is exposed as
--m3-carousel-item-sizeto build one.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Carousel: 22.8 kB
M3 Expressive specs
- Shape
rounded-corner-extra-large- Variants
multi-browse, uncontained, multi-aspect, hero, full-screen
Differences from Compose
- The keylines are a TypeScript port of Compose's
carouselpackage; with 360px, a 186px preferred size and 8px spacing that gives 186 · 118 · 40, mirrored at the end, as Compose does. Uncontained items don't follow keylines: as the spec says, they keep one size and flow past the edge, where Compose shrinks and crops them. - Compose drives a pager; here the carousel scrolls natively and a library-owned mask layer inside each item is translated and clipped on every scroll frame, so the root and slots are never transformed and nothing re-renders while scrolling.
- Hero and full-screen snap one item at a time; a multi-browse fling crosses several items and then snaps; uncontained and multi-aspect scroll freely unless
snap="item". - Padding follows the spec: 16px before and after the items and 8px across them (uncontained and multi-aspect: 16px before only; full-screen: none), set with
contentPadding. As in Compose, items scroll over the start and end padding (the spec: items "bleed over the padding on each side when scrolling"), so the 16px after the items shows only at the end of the scroll, where the last item rests. Unlike Compose, only the large and medium items give up the padding at the ends, so small items never drop below the spec's 40px minimum. - Items are masked with 28px (extra-large) corners, tightening to 20px while pressed (full-screen items have none), on a
surfacefill, and spacing defaults to 8px (16px full-screen). Deviations: no parallax helper, and before hydration items render unmasked at the preferred size.