Skip to content
menumenu tanreiexpand_morecontrasttranslate
tanreiexpand_more
Getting startedWebReactSwiftUIJetpack ComposeFlutterReact NativePresetsYour own design systemUsing Tanrei with AI agentsBrandDesign tokensDesign systems and customizationTheme StudioColorTypographyIconsShapeElevationMotionInteraction statesBehaviourLayoutAccessibilityWordsColor tokensTypescale tokensShape tokensElevation tokensMotion tokensState tokensSpace and measure tokensComponentsButtonMain action buttonSegmented buttonButton groupButton with menuToolbarCopy buttonCheckboxRadio buttonSwitchChipMenuSliderSlider fieldCalendarDateTimePickerField groupRadio groupCheckbox groupSelectSelect fieldMenubarFile uploadFile picker AdvancedDrop zoneText input AdvancedText fieldChip fieldFieldCombobox AdvancedCombobox fieldNumber input AdvancedNumber fieldColor input AdvancedColor fieldOne-time-code input AdvancedOne-time-code fieldEmbedded text input AdvancedChat composerCardDividerModal layer AdvancedDialogListList rowBottom sheetSide sheetCarouselCode blockTablePopoverStepsAccordionDescription listFigureApp shellPage headerTree viewTimelineImage previewHandleResizable frameScroll areaBadgeProgress indicatorMeterNumber tickerLoading indicatorSnackbarTooltipKeyboard shortcutTagInline codeCalloutAvatarEmpty stateTag groupSkeletonFile itemSwatchMarquee textTabsTab viewApp barNavigation barNavigation drawerSearchLinkPaginationPrevious and next linksStepperBreadcrumbsTable of contentsLink cardFAB menuStatusHow Tanrei is builtContributingLicense and attribution
HomeComponentsCarousel

Carousel

A row of visual items that scrolls sideways around one item in focus, each one opening what it shows. A featured row may loop, show its position in dots and advance by itself.

content_copyView as Markdown
Category
Containment
Tokens
comp.carousel
Level
Base

Overview

Web
tanrei-carousel
schedule
SwiftUI
TanreiCarousel
schedule
Jetpack Compose
TanreiCarousel
schedule
Flutter
TanreiCarousel
schedule
React Native
Carousel
schedule

Generated from docs/status/status.json, specs/carousel.spec.json

A revised spec, not yet on every platform

This page describes the carousel as the spec has it now. Independent choices (where the hero sits, fluid or fixed widths, scale, snapping, looping) replace the layout prop, and a featured row can show dots and advance by itself. The hero now sits in the centre by default, and neighbouring items stand one gap apart at every scroll position. The web component already does all of this, and so do the demos. SwiftUI, Compose, Flutter and React Native are marked lagging above: until they catch up they ship the previous revision, with layout and no loop, dots, autoplay or previous and next controls. See The hero is in the centre by default and Moving from layout.

The default: the hero in the centre, a small item beside it

landscapelocation_cityforestwaterterrainkayaking

Usage

A carousel has one kind of item, item. Each platform takes the items the way it takes any repeated children: <tanrei-carousel-item> children on the web, TanreiCarouselItem views in a view builder on SwiftUI, TanreiCarouselItem calls from an item lambda on Compose, TanreiCarouselItem widgets in children on Flutter, and CarouselItem children on React Native.

Each item is one action. It holds your content, usually an image, and emits click when the person activates it (action, onClick, onTap or onPress, depending on the platform). Its label is its accessible name: say what the content shows, such as “Coast path, 12 photos”. The content itself is hidden from assistive technology, and it must not hold a control of its own.

The row is arranged around one item in focus, the hero. A few independent props say how, and each has a default that suits a row to browse: the hero in the centre, the items beside it narrower, and a row that settles at a whole item. itemWidth is the hero’s width; leave it unset to take the design system’s default. A featured row can add loop, the dots (indicator) and autoplay. Without autoplay the carousel has no value to control: it scrolls when the person scrolls it or moves focus.

Over the ends of the row, a previous and a next control move it one item at a time. By default they are drawn for a mouse or a trackpad, and appear while the pointer is over the carousel or focus is in it. Give them a previousLabel and a nextLabel in your product’s language. See The previous and next controls.

The Web and React samples show the current spec. The SwiftUI, Compose, Flutter and React Native samples show the previous revision, which is what those platforms ship: layout (several items in a row by default, hero or uncontained) and itemWidth, with no loop, dots or autoplay.

<tanrei-carousel previous-label="Previous walk" next-label="Next walk" label="Walks near you">
  <tanrei-carousel-item label="Coast path, 12 photos"><img src="coast.jpg" alt="" /></tanrei-carousel-item>
  <tanrei-carousel-item label="Old town, 8 photos"><img src="town.jpg" alt="" /></tanrei-carousel-item>
  <tanrei-carousel-item label="Forest loop, 20 photos"><img src="forest.jpg" alt="" /></tanrei-carousel-item>
</tanrei-carousel>

<!-- A featured row: endless, with dots, advancing by itself. The hero is in the middle by default. -->
<tanrei-carousel previous-label="Previous walk" next-label="Next walk" label="Featured walks" loop indicator autoplay
                 play-label="Play the slideshow" pause-label="Pause the slideshow">…</tanrei-carousel>

<!-- A plain row from the start edge: every item 120 wide (a number of CSS pixels), resting wherever the
     scroll ends. fixed-width and free-scroll are the inverses of fluidWidth and snap, which default to true. -->
<tanrei-carousel previous-label="Previous walk" next-label="Next walk" label="Recently viewed" hero-alignment="start" fixed-width free-scroll item-width="120">…</tanrei-carousel>

<script type="module">
  import '@tanrei/web/components/carousel';
  for (const item of document.querySelectorAll('tanrei-carousel-item')) {
    item.addEventListener('click', () => openWalk(item.label));
  }
  // Only the playback control emits it, not the holds, and not when you set paused.
  document.querySelector('[label="Featured walks"]').addEventListener('pausedchange', (e) => savePaused(e.detail.paused));
</script>
import { Carousel, CarouselItem } from '@tanrei/react';

<Carousel label="Recently viewed" itemWidth={120} fluidWidth={false} snap={false}>
  {walks.map((walk) => (
    <CarouselItem key={walk.id} label={walk.label} onClick={() => openWalk(walk)}>
      <img src={walk.image} alt="" />
    </CarouselItem>
  ))}
</Carousel>

<Carousel label="Featured walks" loop indicator autoplay paused={paused}
  onPausedChange={(e) => setPaused(e.detail.paused)}
  previousLabel="Previous walk" nextLabel="Next walk"
  playLabel="Play the slideshow" pauseLabel="Pause the slideshow">
  {featured.map((walk) => <CarouselItem key={walk.id} label={walk.label} onClick={() => openWalk(walk)}><img src={walk.image} alt="" /></CarouselItem>)}
</Carousel>
import Tanrei

// The previous revision: layout chooses the arrangement. .hero is one featured item at a time.
TanreiCarousel("Featured walks", layout: .hero) {
    ForEach(walks) { walk in
        TanreiCarouselItem(walk.label, action: { open(walk) }) {
            WalkImage(walk)
        }
    }
}
import androidx.compose.ui.unit.dp
import io.github.chnotchy.tanrei.components.TanreiCarousel
import io.github.chnotchy.tanrei.components.TanreiCarouselItem
import io.github.chnotchy.tanrei.components.TanreiCarouselLayout

// The previous revision. An item lambda, as Material's carousels take. itemWidth is a Dp, or null for the token.
// Uncontained is a plain row: every item the same width, cut at the edge.
TanreiCarousel(
    itemCount = walks.size,
    contentDescription = "Recently viewed",
    layout = TanreiCarouselLayout.Uncontained,
    itemWidth = 120.dp,
) { index ->
    val walk = walks[index]
    TanreiCarouselItem(label = walk.label, onClick = { open(walk) }) {
        WalkImage(walk)
    }
}
import 'package:tanrei/tanrei.dart';

// The previous revision: layout chooses the arrangement.
TanreiCarousel(
  semanticLabel: 'Featured walks',
  layout: TanreiCarouselLayout.hero,
  children: [
    for (final Walk walk in walks)
      TanreiCarouselItem(label: walk.label, onTap: () => open(walk), child: WalkImage(walk)),
  ],
),
import { Image } from 'react-native';
import { Carousel, CarouselItem } from '@tanrei/react-native';

// The previous revision's default layout: several items in a row.
<Carousel accessibilityLabel="Walks near you">
  {walks.map((walk) => (
    <CarouselItem key={walk.id} label={walk.label} onPress={() => openWalk(walk)}>
      <Image source={walk.image} style={{ flex: 1 }} />
    </CarouselItem>
  ))}
</Carousel>

Specs

A hero as wide as it may be, and fixed widths that scroll freely from the start edge

landscapelocation_cityforestwaterlandscapelocation_cityforestwaterterrain

Arranging the row: fixed widths, scale, loop, content toward the hero

Fixed widths, resting wherever the scroll ends: fixed-width free-scroll
landscapelocation_cityforestwaterterrain
The others drawn smaller, endless: fixed-width scale-others loop
landscapelocation_cityforestwaterterrain
Endless, both sides always filled: loop
landscapelocation_cityforestwaterterrain
Narrowed items show the side nearest the hero: item-width=“120” content-alignment=“toward-hero” loop
landscapelocation_cityforestwaterterrainkayaking

Dots, autoplay, progress, paused, and the playback control alone

Dots: indicator
landscapelocation_cityforestwaterterrainkayaking
Autoplay with dots and the playback control: indicator autoplay
landscapelocation_cityforestwaterterrainkayaking
The current dot fills until the next item: autoplay-progress
landscapelocation_cityforestwaterterrainkayaking
Paused, by the person or by the product: paused
landscapelocation_cityforestwaterterrainkayaking
Autoplay without dots: the playback control alone
landscapelocation_cityforestwater

Autoplay never runs where the reduced-motion setting is on: there the autoplay demos stand still, without the playback control and the progress.

Anatomy

Properties

Property Type Default Description
heroAlignment start | center "center" Where the item in focus (the hero) sits: in the middle, with items on both sides (the default), or at the inner start edge (the left in a left-to-right language), with items after it only. Not a token axis: geometry, read from the same tokens.
itemWidth number null The width the hero is laid out at, in the platform's unit (CSS px, pt, dp, logical pixels); null takes comp.carousel.container.large-width. With fixed widths every item is this wide (at most the inner width); with fluid widths the hero is kept between a floor and a cap that leave room for the others (CRL-9). Choose it from the content's shape: a product's posters and thumbnails differ.
fluidWidth boolean true Whether item widths change fluidly: true narrows the items beside the hero (on both sides of a hero in the centre) to a medium and a small width, each width following the scroll; false makes every item the hero's width, the ones that do not fit cut by the carousel's edges.
contentAlignment center | toward-hero "center" With fluid widths, where a narrowed item's content is anchored: center shows its middle; toward-hero aligns the items after the hero to their start and the items before it to their end, so each shows the side nearest the hero. Ignored while fluidWidth is false.
scaleOthers boolean false Whether the items other than the hero are drawn smaller, down to comp.carousel.container.min-scale, the scale following the scroll and the gap between drawn items staying the same. It applies with fluid or fixed widths.
snap boolean true Whether the row settles at an item when a scroll ends; false lets it rest wherever the scroll ends.
loop boolean false Whether the row is endless: scrolling past the last item continues to the first, and back. Takes effect only with two or more items; with fewer it is ignored.
navigation auto | always | none "auto" Whether the previous and next controls are drawn over the ends of the row (CRL-41, CRL-42). auto draws them where the primary pointer is fine and can hover — a mouse or a trackpad, where no finger swipes the row — and shows them while the pointer is over the carousel or focus is within it; always draws them on every device and shows them at all times; none draws neither. Keep auto wherever you can: without the controls a person with a mouse moves the row only with Shift and the wheel, or with the indicator where it is drawn, and never with a single press (WCAG 2.5.7).
indicator boolean false Whether the dots are drawn below the items: one per resting position, the current one stretched. For a short featured row; a long row to browse needs none.
autoplay boolean false Whether the row advances by itself, one item every autoplayInterval. It holds while the carousel is hovered, has focus within, is pressed or is hidden, and never runs where motion is reduced (CRL-32 to CRL-34).
autoplayInterval number null How long the row rests at an item before autoplay moves on, in milliseconds; null takes comp.carousel.autoplay.interval. Give text-heavy items more time than images.
paused boolean false Whether autoplay is paused, by the person (with the playback control) or by the product. The playback control changes it and emits pausedChange; a product that sets it emits nothing.
playbackControl boolean true Whether the playback control is drawn while autoplay is on. A product may hide it, but should keep it wherever it can: on touch there is no hover, and without it a person cannot stop the motion (WCAG 2.2.2).
autoplayProgress boolean false Whether the current dot fills to show the time until autoplay moves on. Needs indicator; ignored while autoplay is off or paused.
playLabel string "" The playback control's accessible name while autoplay is paused ("Play the slideshow"). Required while the control can be drawn.
pauseLabel string "" The playback control's accessible name while autoplay is playing ("Pause the slideshow"). Required while the control can be drawn.
previousLabel string "" The previous control's accessible name ("Previous walk"). Required while the control can be drawn.
nextLabel string "" The next control's accessible name ("Next walk"). Required while the control can be drawn.
label string "" Names the carousel's list, and its indicator, for assistive technology ("Recently played"). Required.

Events

Event Description
pausedChange The person paused or played autoplay with the playback control; carries the new paused value. Not emitted when the product sets paused, nor for the holds of CRL-33.

Items

The kinds of item the component repeats. A fixture lists its items in order; each platform names each kind in its own idiom.

item

One item of the row: the product's content in a rounded box, one action named by its label.

Property Type Default Description
label string "" The item's accessible name: what its content shows ("Coast path, 12 photos"). Required; the content itself is not read. It is also the indicator's value text while the item is in focus.
Slot Description
default The item's content. A fixture item's content is the name of a glyph: the harness draws it centred in the content box (the hero's width, the row's height) at sys.icon.medium through the icon helper, with the family and fill of an unselected icon, in the item's content color, on the item's container color.
Event Description
click The item was activated by pointer, touch, keyboard or assistive technology.
Spec Web SwiftUI Jetpack Compose Flutter React Native
Item tanrei-carousel-item TanreiCarouselItem TanreiCarouselItem TanreiCarouselItem CarouselItem
label · Property label label label label label
click · Event click action onClick onTap onPress
Notes A <tanrei-carousel-item> child; its content is its default slot. TanreiCarouselItem(_ label: String, action: @escaping () -> Void) { content }. TanreiCarouselItem(label, onClick) { content }, called from the carousel's item lambda. TanreiCarouselItem(label:, onTap:, child:), one of the carousel's children. <CarouselItem label onPress>{content}</CarouselItem>, a child of Carousel.

States

Behavior

Requirements in EARS form. Every platform implementation is tested against these ids.

ID Requirement
CRL-1 WHEN the user activates an item by pointer, touch, Enter or Space THE carousel SHALL emit that item's click exactly once; a press that turns into a scroll (a drag beyond the platform's touch slop, a fling) SHALL NOT activate the item it started on.
CRL-2 WHILE an item, the indicator or the playback control is hovered, keyboard-focused or pressed THE carousel SHALL render that part's container, content color and opacity, and an item's shape, from the component tokens of its highest-precedence active state, with precedence pressed over focused over hovered; focus gained by pointer or touch SHALL NOT select the focused state.
CRL-3 WHEN an item, the indicator or the playback control receives keyboard focus THE carousel SHALL show the focus ring without animation, inside an item's container, which the row would otherwise clip, and around the indicator's or the playback control's container; focus gained by pointer or touch SHALL NOT show it.
CRL-4 THE carousel SHALL make each item's hit area its drawn container with half of comp.carousel.layout.gap on each side, which for a small item at comp.carousel.container.small-min-width is sys.target.touch wide with the default tokens, and SHALL NOT let the hit area of an item that fills a slot fall below sys.target.pointer wide for a fine pointer or sys.target.touch for touch; a system whose widths give less SHALL still extend the hit area without changing the drawn item, and the row's height SHALL NOT be below the target either. An item on its way between the last slot and an edge slot (CRL-12) is narrower than any slot: its hit area SHALL be its drawn container with half of the gap on each side and no wider, so that it never covers its neighbour's.
CRL-5 WHEN a carousel item or the playback control is pressed by pointer, touch, Enter or Space, or the indicator by pointer or touch, THE carousel SHALL show that part's pressed state without delay and SHALL keep it visible for at least sys.motion.duration.press-hold, even when the press ends sooner; the indicator's SHALL last as long as the press does.
CRL-6 WHILE a carousel item, the indicator or the playback control is pressed THE carousel SHALL answer as sys.behavior.pressed-feedback names: overlay applies the pressed tokens to the whole container at once; ripple grows the pressed state layer from the point of contact (from the center for keyboard activation); dim applies the pressed opacity to the whole control and draws no state layer; none draws no answer to the press. Under ripple and dim only the container color stays with the state under the press; content color, opacity and shape still come from the pressed tokens. Under none every part stays with the state under the press. The ripple grows over comp.carousel.motion.feedback-duration with comp.carousel.motion.state-easing, fades over comp.carousel.motion.state-duration with comp.carousel.motion.state-easing once the press has ended and press-hold has passed, and appears whole where motion is reduced.
CRL-7 THE carousel SHALL ease the corners of its items' containers, the indicator's container and the playback control by sys.shape.corner-smoothing (0 is a quarter circle, 0.6 the iOS continuous corner; a platform with only the OS curve draws it for any amount above 0) and show keyboard focus as sys.behavior.focus-style names (ring or glow); a platform that cannot draw a choice SHALL fall back to the first value and state that in its README.
CRL-8 THE carousel SHALL be as wide as its parent; its row of items SHALL be comp.carousel.layout.height tall unless the product sizes the carousel through the platform's own sizing, in which case the row takes that height less the controls row (CRL-28), and every item SHALL be as tall as the row. It SHALL lay its items out in one row in the order given, comp.carousel.layout.gap apart (g), inside comp.carousel.layout.padding-inline at its start and its end: the inner width W is the carousel's width less that padding twice. Items SHALL scroll under the padding to the carousel's edges and be clipped there.
CRL-9 THE carousel SHALL take L from itemWidth, or from comp.carousel.container.large-width while itemWidth is null, and SHALL make the hero slot H wide. WHILE fluidWidth is false H SHALL be L, at most W. WHILE fluidWidth is true H SHALL be L kept between a floor and a cap: WHILE heroAlignment is center, the floor (W − 4 × g − 2 × comp.carousel.container.small-max-width) / 3 and the cap W − 2 × (g + comp.carousel.container.small-max-width); WHILE heroAlignment is start, the floor (W − 2 × g − comp.carousel.container.small-max-width) / 2 and the cap W − g − comp.carousel.container.small-max-width. IF fluidWidth is true and that cap is less than comp.carousel.container.small-max-width THE carousel SHALL lay the row out as it does with fixed widths (CRL-13), H being W.
CRL-10 WHILE fluidWidth is true THE carousel SHALL fill the width E that the hero slot leaves on each side where items follow it (on both sides, E = (W − H) / 2 − g, WHILE heroAlignment is center; after it, E = W − H − g, WHILE heroAlignment is start) with slots g apart, going outward from the hero: IF E − g is less than 2 × comp.carousel.container.small-min-width, one small slot E wide; otherwise a medium slot M wide and then a small slot S wide, where S is (E − g) / 3 kept between comp.carousel.container.small-min-width and comp.carousel.container.small-max-width and M = E − g − S. IF M is then greater than H, M SHALL be H and S SHALL be E − g − H. Widths SHALL NOT be rounded before the items are placed; CRL-40 says where a platform that draws on whole device pixels puts the rounding.
CRL-11 THE carousel SHALL place the hero slot, where the item in focus sits, WHILE heroAlignment is center with its middle at the middle of the inner width (its start h at (W − H) / 2), and WHILE heroAlignment is start at the inner start edge (h is 0); and SHALL place the other slots of CRL-10, on both sides of it at the centre and after it at the start, each one g beyond the slot before it going outward, measured between the slots' drawn edges.
CRL-12 THE carousel SHALL place its items by a scroll position p, a number of items that advances by one for every H + g the row is scrolled. WHILE loop is not in effect (CRL-27) p SHALL run from 0 to N − 1 (N the number of items), except where CRL-13 ends the range sooner for a hero at the start; the resting positions are the whole numbers in the range and, where the range ends at a fraction, its end, D of them in all, so D is N wherever the range is not ended sooner. Item i, counted from 0, sits at slot position s = i − p. Slot 0 is the hero slot and slots 1, 2 and on follow it toward the end; WHILE heroAlignment is center slots −1, −2 and on precede it toward the start, and WHILE heroAlignment is start no slot precedes it (CRL-10, CRL-11, CRL-13). WHILE fluidWidth is true, beyond the last slot on each side lies an edge slot of no width, g beyond that slot — before a hero at the start, g before the hero slot itself — so that at a whole p nothing is drawn beyond the last slots; an item at or beyond an edge slot SHALL NOT be drawn. An item's start and width SHALL be the linear interpolation between those of the two slots around s. So at p = 0 the first item is the hero and nothing is drawn before it, and as p grows each item moves toward the start, growing from nothing at the edge slot to H as it reaches slot 0 and narrowing again to nothing as it leaves, a hero at the start narrowing against the inner start edge; at the end of the range the last item is the hero and the slots after it are empty.
CRL-13 WHILE fluidWidth is false THE carousel SHALL make every slot H wide, slot k starting at h + k × (H + g), h being the hero slot's start (CRL-11), with no edge slot: the slots go on beyond the carousel's edges, where the items are clipped (CRL-8), so that CRL-12's interpolation starts item i at h + s × (H + g). WHILE scaleOthers is also true the slots other than the hero's take the widths and the places CRL-26 gives them. WHILE heroAlignment is start, scaleOthers is false and loop is not in effect, the range of p SHALL end where the last item ends at the inner end edge, at the greater of 0 and (N × (H + g) − g − W) / (H + g), so that WHILE every item fits in W the row does not scroll.
CRL-14 WHEN the user scrolls the carousel by touch, pen, trackpad, a horizontal wheel or Shift with a vertical wheel THE carousel SHALL follow the scroll; WHILE snap is true, WHEN the scroll ends (a drag released, a wheel or trackpad gesture over) THE carousel SHALL settle at a resting position: the next one in the direction of a fling, or else the nearest one, over comp.carousel.motion.scroll-duration with comp.carousel.motion.scroll-easing, at once where motion is reduced; WHILE snap is false it SHALL come to rest wherever the scroll ends. A fling is a release faster than the platform's minimum fling velocity (Android's ViewConfiguration.getScaledMinimumFlingVelocity, Flutter's kMinFlingVelocity) or, where the platform names none (the web, SwiftUI, React Native), 0.5 points per millisecond. A release's velocity is the pointer's over its last moves: WHERE the pointer has not moved for longer than the time after which the platform's velocity tracker takes a pointer as stopped (40 milliseconds in Android's VelocityTracker, Jetpack Compose's VelocityTracker and Flutter's VelocityTracker) or, where the platform names none (the web, SwiftUI, React Native), 40 milliseconds before the release THE carousel SHALL take the release as having no velocity, so that a drag that stops where it is wanted and is let go there is no fling, however fast it moved before it stopped. A horizontal wheel, a trackpad and Shift with a vertical wheel are physical in every layout direction: THE carousel SHALL move the row the way the platform's own scrolling containers move for that input and SHALL NOT reverse it in a right-to-left layout, so that Shift with a wheel turned down, which brings into view what lies further to the right, moves toward later items in left-to-right and toward earlier items in right-to-left.
CRL-15 THE carousel SHALL lay each item's content out H wide and as tall as the row, and SHALL clip it to the item's container and its comp.carousel.container.shape corners; WHILE fluidWidth is false or contentAlignment is center the content SHALL be centred on the container, and WHILE fluidWidth is true and contentAlignment is toward-hero an item after the hero (s above 0) SHALL align the content's start edge with its container's start edge and an item before it (s below 0) the content's end edge with its container's end edge, so that a narrowed item shows the side of its content nearest the hero and the content glides inside the item as it widens and narrows.
CRL-16 THE carousel SHALL fill each item's container with comp.carousel.item.container.color at rest, under its content, whatever the item's state, and SHALL hand the content comp.carousel.item.content.color as the platform's inherited foreground (the web's inherited color, SwiftUI's foreground style, Compose's content color, Flutter's default text and icon style, React Native's Tanrei text context). Because an item's content usually covers it (an image), the carousel SHALL draw the state layer over the content: comp.carousel.item.state-layer.color at sys.state.hover-state-layer-opacity, sys.state.focus-state-layer-opacity or sys.state.pressed-state-layer-opacity for the item's highest-precedence state, and the ripple of CRL-6 in the same layer, so hover, focus and press show on any content; the container color under the content is the resting fill only.
CRL-17 THE carousel SHALL be at most five Tab stops, in this order: the playback control while it is drawn (CRL-35), so that the motion can be stopped before anything else is reached; the previous and then the next control while they are drawn (CRL-41), before the items, so that a person can move the row before reading it; the items, as one stop, at the item that last had keyboard focus in it or else at the resting item (the item at slot 0 while fluidWidth is true, heroAlignment is center or snap is true, and otherwise the first item wholly in view); and the indicator while it is drawn (CRL-29). WHILE an item has keyboard focus Right Arrow and Left Arrow SHALL move focus to the next and previous item, from the last to the first and the first to the last WHILE loop is in effect and otherwise without wrapping, and Home and End to the first and last item; in a right-to-left layout Left Arrow SHALL move to the next item and Right Arrow to the previous.
CRL-18 WHEN an item receives keyboard focus or assistive-technology focus THE carousel SHALL scroll, over comp.carousel.motion.scroll-duration with comp.carousel.motion.scroll-easing (at once where motion is reduced), so that WHILE fluidWidth is true, heroAlignment is center or snap is true the item sits at slot 0 or, where the range ends first, at the resting position nearest it, going the shorter way round WHILE loop is in effect; and otherwise so that the whole item is in view, scrolling as little as that needs.
CRL-19 THE carousel SHALL expose its items as a list named by label, and each item as one element with the button role, named by its label, with its position among the items and their number; it SHALL hide each item's content from assistive technology (the label names the item), and SHALL keep items that are out of view exposed, in order, so that a screen reader reaches every item (CRL-18 brings it into view). The indicator (CRL-31), the playback control (CRL-35) and the previous and next controls (CRL-41) SHALL be outside the list and SHALL NOT be counted among its items.
CRL-20 WHILE an item's label is empty THE carousel SHALL still render it, and in debug builds report that it has no accessible name; WHILE the carousel's label is empty it SHALL report that the list and the indicator have no name; WHILE autoplay and playbackControl are true and playLabel or pauseLabel is empty it SHALL report the missing name; WHILE the previous and next controls are drawn (CRL-41) and previousLabel or nextLabel is empty it SHALL report the missing name; and WHILE indicator is true and the dots do not fit (CRL-29) it SHALL report that they are not drawn. An item's content SHALL contain no interactive element; a platform that can inspect it (the web, on every slot change) SHALL report one in debug builds, and a platform that cannot SHALL state the rule in its README.
CRL-21 WHEN the carousel's width or its items change THE carousel SHALL arrange its slots again and keep the resting item (CRL-17) where it was, as far as the new range allows, without motion; WHEN the number of items falls below two it SHALL stop looping (CRL-27) and advancing (CRL-32), and no longer draw the indicator, the playback control or the previous and next controls.
CRL-22 WHEN the colors of an item, the indicator or the playback control change between states THE carousel SHALL animate them over comp.carousel.motion.state-duration with comp.carousel.motion.state-easing, and SHALL change them at once where motion is reduced.
CRL-23 WHEN the layout direction is right-to-left THE carousel SHALL mirror its row and its controls row: the inner start edge at the right, items moving toward the right as p grows, the padding, the scroll direction, the start and end sides of contentAlignment, the order of the dots, the playback control's side and the sides of the previous and next controls (the previous control at the right) all mirrored; it SHALL grow a ripple from the point of contact as in left-to-right, and SHALL NOT mirror an item's content or the pause and play_arrow glyphs. The chevron_left and chevron_right glyphs of the previous and next controls SHALL be drawn mirrored exactly when the system's icon set marks the name as mirrored, by the Button's own icon helper; THE carousel SHALL NOT mirror a glyph itself.
CRL-24 WHEN heroAlignment, contentAlignment or navigation names a value the carousel does not define THE carousel SHALL render with that prop's default value, and in debug builds report the unknown value; WHEN itemWidth or autoplayInterval is not a positive number THE carousel SHALL treat it as null and in debug builds report it.
CRL-25 WHILE the text size is enlarged THE carousel SHALL keep its height, slots and items as they are: it holds no text of its own, and an item's content follows the text size itself.
CRL-26 WHILE scaleOthers is true THE carousel SHALL give the hero slot the scale 1 and every other slot the scale comp.carousel.container.min-scale, and SHALL draw each item's container at the scale interpolated between the two slots around s, which is 1 − (1 − comp.carousel.container.min-scale) × the lesser of 1 and |s|: as tall as the row times that scale, centred on the row's height, with its content drawn at that scale. WHILE fluidWidth is false a slot SHALL also be H times its scale wide, and the slots SHALL be placed g apart from drawn edge to drawn edge going outward from the hero slot, so that the smaller items close up to their neighbours; WHILE fluidWidth is true the slots keep the widths of CRL-10, which already fill the row, and only the height and the content take the scale. The corners of a scaled container SHALL stay the radius of comp.carousel.container.shape (or of its state's shape token) and SHALL NOT be multiplied by the scale; the item's focus ring SHALL be drawn at its own width inside the drawn container, and the item's hit area (CRL-4) SHALL follow the drawn container. The scale SHALL follow the scroll where motion is reduced as well, because the person's own scroll drives it.
CRL-27 WHILE loop is true and there are at least two items THE carousel SHALL scroll without end in both directions: p SHALL take any value, every whole number SHALL be a resting position, and item i SHALL sit at the one slot position s that differs from i − p by a whole multiple of N and lies above −N / 2 and at most N / 2 WHILE heroAlignment is center, or above −1 and at most N − 1 WHILE heroAlignment is start, so that scrolling past the last item continues to the first and before the first to the last. Each item SHALL be drawn once: with fluid widths and enough items for every slot and both edge slots an item passes from one side to the other at the edge slots, where it has no width, and with fewer items, or with fixed widths and too few items to reach beyond both edges, a slot stays empty and an item that passes to the other side may appear there at once. WHILE there are fewer than two items THE carousel SHALL ignore loop; loop is in effect only while both conditions hold.
CRL-28 WHILE the indicator (CRL-29) or the playback control (CRL-35) is drawn THE carousel SHALL draw, directly below its row of items, a controls row as wide as the carousel and comp.carousel.controls.height tall that does not scroll, with the indicator's container centred on the carousel's width and the playback control at its inline end, its end edge at the inner end edge, both centred on the row's height; WHILE neither is drawn there SHALL be no controls row. The indicator SHALL stay centred whether or not the playback control is drawn.
CRL-29 WHILE indicator is true and there are at least two resting positions THE carousel SHALL draw the indicator: D dots in reading order, comp.carousel.dot.gap apart, each comp.carousel.dot.size tall with round ends, inside a container that reaches comp.carousel.controls.indicator-padding-inline beyond the first and last dot, is comp.carousel.controls.button-size tall and has comp.carousel.controls.shape corners. The indicator's position q follows p: between resting positions j and j + 1 it runs linearly from j to j + 1, and WHILE loop is in effect q is p less a whole multiple of N, from 0 up to N, its distance to a dot measured around the ring. Dot j SHALL be comp.carousel.dot.size + (comp.carousel.dot.active-width − comp.carousel.dot.size) × w wide, w being the greater of 0 and 1 − the distance from q to j, and SHALL be drawn in comp.carousel.dot.color with a fill of comp.carousel.indicator.content.color over it at opacity w, across its whole width unless CRL-36 says otherwise, so that the current dot is stretched and in the active color and the stretch and the color pass to the next dot as the row scrolls. IF the container would be wider than W − 2 × (sys.target.touch + g) THE carousel SHALL NOT draw the indicator.
CRL-30 WHEN the person presses the indicator by pointer or touch anywhere in its hit area THE carousel SHALL move the row to the resting position of the dot nearest the press and, while the press moves along the dots, to the dot nearest it, each move over comp.carousel.motion.scroll-duration with comp.carousel.motion.scroll-easing (at once where motion is reduced); WHILE the indicator has keyboard focus Right Arrow and Left Arrow SHALL move the row to the next and previous resting position (wrapping WHILE loop is in effect, and otherwise not), Home and End to the first and last, mirrored in a right-to-left layout; WHEN assistive technology increments or decrements the indicator it SHALL move by one resting position. Focus SHALL stay on the indicator, and the items' Tab stop (CRL-17) SHALL become the resting item the move brings.
CRL-31 THE carousel SHALL expose the indicator as one slider (the adjustable trait on Apple platforms), named by label, horizontal, with the lowest value 1, the highest D and the value of the resting position nearest q counted from 1, and SHALL give it as value text the label of the item that position brings to slot 0 or, where the range ends first, the resting item there; its dots SHALL NOT be exposed one by one.
CRL-32 WHILE autoplay is true, paused is false, there are at least two resting positions, motion is not reduced (CRL-34) and no hold of CRL-33 is in effect THE carousel SHALL advance to the next resting position each time autoplayInterval (or comp.carousel.autoplay.interval while it is null) has passed with the row at rest, scrolling over comp.carousel.motion.autoplay-duration with comp.carousel.motion.autoplay-easing; from the last resting position it SHALL go on to the first, forward WHILE loop is in effect and otherwise back across the row over the same duration. An advance SHALL NOT move focus, change the items' Tab stop, or make an announcement.
CRL-33 WHILE a pointer is over the carousel (its row or its controls row), focus is anywhere within it however it came there, the person is pressing or dragging the row or the indicator, or the platform reports the carousel's window or document hidden, THE carousel SHALL NOT advance and SHALL hold the time that has passed; WHEN the last hold ends it SHALL continue from the time it held. WHEN the person moves the row (a scroll, a key, the indicator, the previous or the next control) the time SHALL start again from zero once the row comes to rest. WHEN the person activates the playback control to play, the hover and focus holds in effect at that moment SHALL end, and each SHALL apply again only once the pointer or focus has left the carousel and entered it again.
CRL-34 WHILE motion is reduced THE carousel SHALL NOT advance by itself, whatever autoplay and paused say, and SHALL NOT draw the playback control or the autoplay progress; WHEN motion stops being reduced it SHALL start autoplay again (paused permitting) with the time from zero. Where motion is reduced the width, the scale and the dots SHALL still follow a scroll the person makes.
CRL-35 WHILE autoplay is true, playbackControl is true, there are at least two resting positions and motion is not reduced THE carousel SHALL draw the playback control in the controls row: an icon-only button, a comp.carousel.controls.button-size square with comp.carousel.controls.shape corners, filled with comp.carousel.playback.container.color, holding the icon set's pause glyph while paused is false and play_arrow while paused is true, comp.carousel.controls.icon.size, in comp.carousel.playback.content.color, with the family and fill of an unselected icon, sys.icon.weight and its optical size clamped to sys.icon.optical-size.min and sys.icon.optical-size.max. It SHALL be exposed with the button role, named by pauseLabel while paused is false and by playLabel while paused is true, with no pressed or selected state. WHEN the person activates it THE carousel SHALL toggle paused, emit pausedChange with the new value and keep focus on it, and on play the time SHALL start from zero; WHEN the product sets paused THE carousel SHALL emit nothing.
CRL-36 WHILE autoplayProgress is true, the indicator is drawn, autoplay is true, paused is false and motion is not reduced THE carousel SHALL draw the fill of CRL-29 only on the dot of the resting position the row last came to rest at, from that dot's start edge across the part of its width that the time passed (CRL-33) is of the interval, growing with the time and stopping while a hold is in effect, and on no other dot, so that the dot stands in comp.carousel.dot.color and fills with comp.carousel.indicator.content.color until the row moves on, the fill fading as the dot narrows.
CRL-37 THE carousel SHALL give the playback control a hit area centred on it of at least sys.target.touch for touch and sys.target.pointer for a fine pointer, and the indicator a hit area as tall as the controls row and as wide as its container, at least sys.target.touch wide; with the default tokens both fit inside the controls row, and CRL-29 keeps them apart.
CRL-38 WHILE the icon set's font has not loaded THE carousel SHALL keep the playback control's glyph box and draw nothing in it, never the glyph's name as text.
CRL-39 THE carousel SHALL take its layout direction from where it is used — the direction of the nearest ancestor that sets one, and the platform's own where none does — and SHALL have no direction setting of its own; WHEN that direction changes while the carousel is shown THE carousel SHALL draw itself for the new direction at once, without a motion of its own, keeping the item at rest (the same item in reading order, not the same scroll offset), its playback and its focus.
CRL-40 THE carousel SHALL keep the distance from the drawn end edge of an item's container to the drawn start edge of the next item's container equal to comp.carousel.layout.gap, for every two neighbouring items that are both drawn, at every scroll position: at rest and at every moment of a drag, a fling, a settle, an advance and a move by the keys or the dots, in every combination of heroAlignment, fluidWidth, scaleOthers, contentAlignment, snap and loop, and in both layout directions. The edges are those of the container as it is drawn, after any scale (CRL-26), not those of a box laid out before the scale. THE carousel SHALL place every item it draws in a frame from the same scroll position p, and SHALL NOT ease, delay or animate an item's start, width or scale apart from p. A platform that draws on whole device pixels SHALL round each item's start edge and take its end edge from the next item's rounded start edge less the gap as that platform rounds it, so that the rounding falls on an item's width and never on a gap, and no two gaps in view differ.
CRL-41 WHILE navigation is auto or always and there are at least two resting positions THE carousel SHALL draw a previous control over the inline start of its row and a next control over its inline end, above the items: the previous control's start edge at the inner start edge and the next control's end edge at the inner end edge, both centred on the row's height. They SHALL be icon-only Buttons of the medium size in the variant comp.carousel.navigation.button.variant names, given through the channel a Button reads from the component that places it and otherwise unrestyled, showing the icon set's chevron_left and chevron_right glyphs and named by previousLabel and nextLabel. WHILE navigation is auto THE carousel SHALL draw them only where the primary pointer is fine and can hover; WHILE navigation is none, or there are fewer than two resting positions, it SHALL draw neither.
CRL-42 WHILE navigation is auto THE carousel SHALL show the previous and next controls only while a pointer is over the carousel (its row or its controls row) or focus is within it, however it came there, fading them in and out over comp.carousel.motion.state-duration with comp.carousel.motion.state-easing, at once where motion is reduced; hidden, they SHALL keep their place in the Tab order (CRL-17) and stay exposed to assistive technology with their names and states, so that a keyboard reaches them and focus shows them. WHILE navigation is always THE carousel SHALL show them at all times.
CRL-43 WHEN the person activates the previous or the next control THE carousel SHALL move the row to the resting position before or after the one it is at — while it is moving, the one it is moving to; between two resting positions, the nearest one before or after where it is — over comp.carousel.motion.scroll-duration with comp.carousel.motion.scroll-easing (at once where motion is reduced), from the first to the last and from the last to the first WHILE loop is in effect. Focus SHALL stay on the control, and the items' Tab stop (CRL-17) SHALL become the resting item the move brings. WHILE loop is not in effect THE carousel SHALL disable the previous control while the row is at, or moving to, the first resting position, and the next control at the last: drawn and exposed as disabled and refusing activation, but kept in the Tab order and keeping focus, so that the stops do not change as the row moves and focus is never lost when a control reaches its end.

Platform name mapping

Parity does not mean identical APIs. Each platform uses its own idiom for the same contract.

Spec Web SwiftUI Jetpack Compose Flutter React Native
Component tanrei-carousel TanreiCarousel TanreiCarousel TanreiCarousel Carousel
heroAlignment · Property heroAlignment heroAlignment heroAlignment heroAlignment heroAlignment
itemWidth · Property itemWidth itemWidth itemWidth itemWidth itemWidth
fluidWidth · Property fluidWidth fluidWidth fluidWidth fluidWidth fluidWidth
contentAlignment · Property contentAlignment contentAlignment contentAlignment contentAlignment contentAlignment
scaleOthers · Property scaleOthers scaleOthers scaleOthers scaleOthers scaleOthers
snap · Property snap snap snap snap snap
loop · Property loop loop loop loop loop
navigation · Property navigation navigation navigation navigation navigation
indicator · Property indicator showsIndicator indicator indicator indicator
autoplay · Property autoplay autoplay autoplay autoplay autoplay
autoplayInterval · Property autoplayInterval autoplayInterval autoplayInterval autoplayInterval autoplayInterval
paused · Property paused isPaused paused paused paused
playbackControl · Property playbackControl showsPlaybackControl playbackControl playbackControl playbackControl
autoplayProgress · Property autoplayProgress showsAutoplayProgress autoplayProgress autoplayProgress autoplayProgress
playLabel · Property playLabel playLabel playLabel playLabel playLabel
pauseLabel · Property pauseLabel pauseLabel pauseLabel pauseLabel pauseLabel
previousLabel · Property previousLabel previousLabel previousLabel previousLabel previousLabel
nextLabel · Property nextLabel nextLabel nextLabel nextLabel nextLabel
label · Property label label contentDescription semanticLabel accessibilityLabel
pausedChange · Event pausedchange isPaused onPausedChange onPausedChanged onPausedChange
Notes Attributes: hero-alignment, item-width (a number of CSS pixels; without it the property is null), content-alignment, scale-others, loop, indicator, autoplay, autoplay-interval (milliseconds), paused, autoplay-progress, play-label, pause-label, navigation (reflected), previous-label, next-label. fluidWidth, snap and playbackControl are boolean properties that default to true; their attributes are the inverses fixed-width, free-scroll and no-playback-control (an HTML boolean attribute cannot default to true). pausedchange is a CustomEvent whose detail.paused is the new value. Built on a native horizontal scroller (so wheel, trackpad and touch scroll as the platform does) whose track is as long as the scroll range; the items are placed from its scroll offset (CRL-12), and the settle animates the scroll offset over comp.carousel.motion.scroll-duration and scroll-easing once the scroll ends (scrollend, or 100 ms without a scroll event, because not every engine sends scrollend after a wheel), since a smooth scrollTo cannot follow the tokens. Fling 0.5 px/ms, measured from the finger's last touch moves over their own time stamps; after a fling the settle starts at the release, and the browser's momentum is held until it ends. While loop is in effect the track is several turns long and the offset is moved by a whole number of turns (N × (H + g)) when the row rests near either end, which draws nothing new. Autoplay reads prefers-reduced-motion and document.visibilityState when it would advance and listens for their changes; the hover hold is pointerenter / pointerleave on the host, the focus hold focusin / focusout. The items are placed from one scroll position in one pass, each start rounded to a device pixel and each end taken from the next start (CRL-40). The previous and next controls are <tanrei-button> elements with focusable-when-disabled, given their variant through the Button's group-item channel; auto draws them under (hover: hover) and (pointer: fine) and shows them while the host matches :hover or :focus-within. Snapshot harness: a 400 × 200 stage (the carousel fills it: W 368), or 400 × 248 for the fixtures with a controls row, on a surface page, scrolled to its start, the pointer outside, motion not reduced and the autoplay clock stopped at the start of its interval. Lagging: ships an earlier revision of this spec, with layout and its three values, and no loop, dots or autoplay, and so owes the hero centred by default, the edge slots of no width, the scaled slots closed up and the constant gap as well (CRL-9 to CRL-13, CRL-26, CRL-40), and the previous and next controls with their props navigation, previousLabel and nextLabel (CRL-41 to CRL-43). Target API: TanreiCarousel(_ label: String, heroAlignment: .center, itemWidth: CGFloat? = nil, fluidWidth: true, contentAlignment: .center, scaleOthers: false, snap: true, loop: false, showsIndicator: false, autoplay: false, autoplayInterval: Duration? = nil, isPaused: Binding<Bool>, showsPlaybackControl: true, showsAutoplayProgress: false, playLabel:, pauseLabel:) { TanreiCarouselItem(…) { … } }; pausedChange is the isPaused binding, set only by the control. A horizontal ScrollView whose content is a track as long as the scroll range, the items placed from the scroll offset by a custom Layout (read from scrollPosition and the track's geometry), settled by a custom ScrollTargetBehavior (iOS 17). The list is an accessibilityElement(children: .contain) named by label, and each item a button. SwiftUI has no position-in-set property for a custom container, so VoiceOver's own count of the container's elements stands in; the README says so. Autoplay reads accessibilityReduceMotion and scenePhase. Snapshot harness: a 400 × 200 frame (400 × 248 with a controls row) on a surface page. Lagging: ships an earlier revision of this spec, with layout and its three values, and no loop, dots or autoplay, and so owes the hero centred by default, the edge slots of no width, the scaled slots closed up and the constant gap as well (CRL-9 to CRL-13, CRL-26, CRL-40), and the previous and next controls with their props navigation, previousLabel and nextLabel (CRL-41 to CRL-43). Target API: TanreiCarousel(itemCount, contentDescription, heroAlignment, itemWidth: Dp? = null, fluidWidth = true, contentAlignment, scaleOthers = false, snap = true, loop = false, indicator = false, autoplay = false, autoplayInterval: Duration? = null, paused = false, onPausedChange, playbackControl = true, autoplayProgress = false, playLabel, pauseLabel) { index -> TanreiCarouselItem(…) { … } }, as Material's carousels take an item lambda; built on Modifier.scrollable and a custom Layout, not Material's carousel (the package does not depend on Material). Settling uses a SnapFlingBehavior whose fling threshold is ViewConfiguration's. No list role: collectionInfo on the row and collectionItemInfo with Role.Button on each item. Autoplay reads the animator duration scale (0 is reduced motion) and the lifecycle's resumed state. Snapshot harness: a 400 × 200 dp box (400 × 248 with a controls row) on a surface page. Lagging: ships an earlier revision of this spec, with layout and its three values, and no loop, dots or autoplay, and so owes the hero centred by default, the edge slots of no width, the scaled slots closed up and the constant gap as well (CRL-9 to CRL-13, CRL-26, CRL-40), and the previous and next controls with their props navigation, previousLabel and nextLabel (CRL-41 to CRL-43). Target API: TanreiCarousel(semanticLabel:, heroAlignment: TanreiCarouselHeroAlignment.center, itemWidth: null, fluidWidth: true, contentAlignment: TanreiCarouselContentAlignment.center, scaleOthers: false, snap: true, loop: false, indicator: false, autoplay: false, autoplayInterval: null, paused: false, onPausedChanged:, playbackControl: true, autoplayProgress: false, playLabel:, pauseLabel:, children: [...]), built on the widgets library's Scrollable with a custom layout and ScrollPhysics that settle (CRL-14), not Material's CarouselView. Each item is Semantics(button: true, label:) inside IndexedSemantics, and the scrollable reports semanticChildCount, so the position and the number of items are read; the whole is a Semantics(label:, explicitChildNodes: true) container. Autoplay reads MediaQuery.disableAnimationsOf and the app lifecycle. Snapshot harness: a golden of a 400 × 200 surface (400 × 248 with a controls row) on a surface page. Lagging: ships an earlier revision of this spec, with layout and its three values, and no loop, dots or autoplay, and so owes the hero centred by default, the edge slots of no width, the scaled slots closed up and the constant gap as well (CRL-9 to CRL-13, CRL-26, CRL-40), and the previous and next controls with their props navigation, previousLabel and nextLabel (CRL-41 to CRL-43). Target API: <Carousel accessibilityLabel heroAlignment itemWidth fluidWidth contentAlignment scaleOthers snap loop indicator autoplay autoplayInterval paused onPausedChange playbackControl autoplayProgress playLabel pauseLabel>{items}</Carousel>: a horizontal ScrollView whose content is as long as the scroll range, the items placed from an Animated value of its offset; it settles with scrollTo after the drag or momentum ends (fling 0.5 pt/ms). The carousel has role="list" and each item the button role. React Native has no position-in-set property, so an item's position and the number of items are left to the screen reader's own count of the list; the README says so. Autoplay reads AccessibilityInfo.isReduceMotionEnabled and AppState. No virtualization. Snapshot harness: a 400 × 200 view (400 × 248 with a controls row) on a surface page.

Tokens

Token Aliases Resolved (light)
--tanrei-comp-carousel-autoplay-interval — 5000ms
--tanrei-comp-carousel-container-large-width — 200px
--tanrei-comp-carousel-container-min-scale — 0.85
--tanrei-comp-carousel-container-shape sys.shape.corner.large 12px
--tanrei-comp-carousel-container-small-max-width — 56px
--tanrei-comp-carousel-container-small-min-width — 40px
--tanrei-comp-carousel-controls-button-size — 40px
--tanrei-comp-carousel-controls-height sys.target.touch 48px
--tanrei-comp-carousel-controls-icon-size sys.icon.medium 24px
--tanrei-comp-carousel-controls-indicator-padding-inline sys.space.space150 12px
--tanrei-comp-carousel-controls-shape sys.shape.corner.full 9999px
--tanrei-comp-carousel-dot-active-width — 24px
--tanrei-comp-carousel-dot-color sys.color.outline #848484
--tanrei-comp-carousel-dot-gap sys.space.space100 8px
--tanrei-comp-carousel-dot-size — 8px
--tanrei-comp-carousel-focused-container-shape — 12px
--tanrei-comp-carousel-focused-opacity — 1
--tanrei-comp-carousel-hovered-container-shape — 12px
--tanrei-comp-carousel-hovered-opacity — 1
--tanrei-comp-carousel-indicator-container-color — #000000 · 0%
--tanrei-comp-carousel-indicator-content-color sys.color.primary #1b1b1b
--tanrei-comp-carousel-indicator-focused-container-color — #1b1b1b · 10%
--tanrei-comp-carousel-indicator-focused-content-color — #1b1b1b
--tanrei-comp-carousel-indicator-focused-state-layer-color — #1b1b1b
--tanrei-comp-carousel-indicator-hovered-container-color — #1b1b1b · 8%
--tanrei-comp-carousel-indicator-hovered-content-color — #1b1b1b
--tanrei-comp-carousel-indicator-hovered-state-layer-color — #1b1b1b
--tanrei-comp-carousel-indicator-pressed-container-color — #1b1b1b · 10%
--tanrei-comp-carousel-indicator-pressed-content-color — #1b1b1b
--tanrei-comp-carousel-indicator-pressed-state-layer-color — #1b1b1b
--tanrei-comp-carousel-indicator-state-layer-color comp.carousel.indicator.content.color #1b1b1b
--tanrei-comp-carousel-item-container-color sys.color.surface-container-highest #eeeeee
--tanrei-comp-carousel-item-content-color sys.color.on-surface #1b1b1b
--tanrei-comp-carousel-item-focused-container-color — #d9d9d9
--tanrei-comp-carousel-item-focused-content-color — #1b1b1b
--tanrei-comp-carousel-item-focused-state-layer-color — #1b1b1b
--tanrei-comp-carousel-item-hovered-container-color — #dddddd
--tanrei-comp-carousel-item-hovered-content-color — #1b1b1b
--tanrei-comp-carousel-item-hovered-state-layer-color — #1b1b1b
--tanrei-comp-carousel-item-pressed-container-color — #d9d9d9
--tanrei-comp-carousel-item-pressed-content-color — #1b1b1b
--tanrei-comp-carousel-item-pressed-state-layer-color — #1b1b1b
--tanrei-comp-carousel-item-state-layer-color comp.carousel.item.content.color #1b1b1b
--tanrei-comp-carousel-layout-gap sys.space.space100 8px
--tanrei-comp-carousel-layout-height — 200px
--tanrei-comp-carousel-layout-padding-inline sys.space.space200 16px
--tanrei-comp-carousel-motion-autoplay-duration sys.motion.duration.long2 500ms
--tanrei-comp-carousel-motion-autoplay-easing sys.motion.easing.standard cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-carousel-motion-feedback-duration sys.motion.role.feedback 450ms
--tanrei-comp-carousel-motion-scroll-duration sys.motion.duration.medium2 300ms
--tanrei-comp-carousel-motion-scroll-easing sys.motion.easing.emphasized-decelerate cubic-bezier(0.05, 0.7, 0.1, 1)
--tanrei-comp-carousel-motion-state-duration sys.motion.role.state.large 250ms
--tanrei-comp-carousel-motion-state-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-carousel-navigation-button-variant — 2
--tanrei-comp-carousel-playback-container-color — #000000 · 0%
--tanrei-comp-carousel-playback-content-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-carousel-playback-focused-container-color — #4b4b4b · 10%
--tanrei-comp-carousel-playback-focused-content-color — #4b4b4b
--tanrei-comp-carousel-playback-focused-state-layer-color — #4b4b4b
--tanrei-comp-carousel-playback-hovered-container-color — #4b4b4b · 8%
--tanrei-comp-carousel-playback-hovered-content-color — #4b4b4b
--tanrei-comp-carousel-playback-hovered-state-layer-color — #4b4b4b
--tanrei-comp-carousel-playback-pressed-container-color — #4b4b4b · 10%
--tanrei-comp-carousel-playback-pressed-content-color — #4b4b4b
--tanrei-comp-carousel-playback-pressed-state-layer-color — #4b4b4b
--tanrei-comp-carousel-playback-state-layer-color comp.carousel.playback.content.color #4b4b4b
--tanrei-comp-carousel-pressed-container-shape — 12px
--tanrei-comp-carousel-pressed-opacity — 1

Fixtures

Canonical renderings. Every platform snapshots each fixture under the same id so the results can be compared.

Generated from specs/carousel.spec.json, tokens/comp/carousel.tokens.json, design/tokens/

Guidelines

When to use

Use a carousel for a row of visual items that people browse and open one at a time: albums, places, products, episodes. It shows that more items follow without taking the height of a grid, and it gives the items in view more room than the ones about to arrive.

Use a list when the items are mostly text, or when people compare or choose among them. Use cards in a grid when every item needs its own text and actions. Make a carousel advance by itself only for a short featured row, and keep its playback control.

Arranging the row

Each prop answers one question, and they combine freely.

Prop Default What it decides
heroAlignment center Where the item in focus sits: in the center with items on both sides, or at the inner start edge with items after it only.
itemWidth The design system’s The hero’s width. With fixed widths, every item’s width.
fluidWidth true True narrows the items beside the hero to a medium and a small width, each width following the scroll. False makes every item the hero’s width, the last one in view cut by the edge.
contentAlignment center With fluid widths, which part of a narrowed item’s content shows: its middle, or the side nearest the hero (toward-hero).
scaleOthers false Draws the items other than the hero smaller, following the scroll, with fluid or fixed widths. The gap between items stays the same: with fixed widths the smaller items close up to their neighbours.
snap true Settles at a whole item when a scroll ends, or rests wherever it ends.
loop false Makes the row endless: past the last item comes the first. Only with two or more items.

fluidWidth is fixed-width on the web and snap is free-scroll, as the inverses of props that default to true.

A few common rows:

For Set
Browsing many items: albums, places Nothing: the defaults.
One featured item at a time, with a glimpse of the next An itemWidth at least as wide as the carousel. The hero takes the widest it may be.
A featured row with items on both sides Nothing more: the hero is in the centre by default. Often with loop, so both sides are always filled.
A row that starts at the edge, the hero first heroAlignment start.
A plain scrolling row, such as recently viewed items heroAlignment start, fluidWidth false and snap false.

Choose itemWidth from the shape of your content: square covers, tall posters and wide thumbnails want different widths, even in one product. With fluid widths the hero keeps room for the others: it never grows past the width that leaves a small item on each side where items follow, and never shrinks below the width that keeps the next item no wider than itself. On a row too narrow for that, the carousel shows one item at a time, as wide as the row.

The hero is in the centre by default

Two things differ from the previous revision. Until the other platforms catch up, this is the web’s behaviour.

  • heroAlignment now defaults to center. It was start. Both values remain.
  • Neighbouring items are one gap apart at every scroll position, not only at rest. Before, the gap grew as an item passed the row’s edge, and a scaled item left extra space around it.
You had Now
No heroAlignment The hero is in the centre, with a narrower item on each side. To keep the row as it was, set heroAlignment to start (hero-alignment="start" on the web).
heroAlignment start Nothing to change.
heroAlignment center Nothing to change. You may remove the prop.
scaleOthers with fixed widths The smaller items now stand one gap from their neighbours, closer than before. Nothing to change.
An itemWidth wider than the row, no heroAlignment The hero is narrower than before, because a small item stays on each side. Set heroAlignment to start for the widest hero.

With fluid widths an item now enters the row from nothing at the edge and grows as it comes in, instead of sliding in at its full width. At rest the row looks as it did.

Moving from layout

The previous revision’s layout prop is removed. Each of its values is now a combination of the props above:

Previous layout Now
Left at its default heroAlignment start. On a row no wider than a phone the picture is the same. On a wider row the hero grows as far as its limit.
hero heroAlignment start and an itemWidth at least as wide as the carousel, so the hero takes the widest it may be. The same picture.
uncontained heroAlignment start, fluidWidth false and snap false (hero-alignment="start" fixed-width free-scroll on the web). The same picture.

Dots, autoplay and the playback control

  • Dots. indicator draws one dot per resting position in a row below the items, centred on the carousel. The current dot is stretched, and the stretch passes from one dot to the next as the row scrolls. The dots are one control: press or drag anywhere on them to move the row. Use them for a short featured row. If there are too many to fit beside the playback control, they are not drawn, and debug builds say so.
  • Autoplay. autoplay moves the row on by one item every autoplayInterval milliseconds (5 seconds in the default system). Give text-heavy items more time than images. Without loop, it goes back to the first item after the last. It never moves focus and announces nothing.
  • Holds. Autoplay holds while the pointer is over the carousel, while focus is anywhere in it, while it is pressed or dragged, and while the window is hidden. When the last hold ends it continues where it stopped; after the person moves the row, the interval starts again.
  • Reduced motion. Where the platform’s reduced-motion setting is on, autoplay never runs, and the playback control and the progress are not drawn. The widths, the scale and the dots still follow the person’s own scroll.
  • The playback control. While autoplay is on, a round button at the end of the dots’ row pauses and plays it, showing pause or play_arrow. It is named by pauseLabel or playLabel, whichever it would do. It changes paused and emits pausedChange (pausedchange on the web); your code may also set paused, which emits nothing.
  • Progress. With autoplayProgress, the current dot fills as the time until the next item passes.

Keep playback controllable. A product may hide the playback control with playbackControl false, but it should keep it wherever it can. The holds are not a way to stop the motion: touch has no hover, a finger holds the row only while it rests there, and a screen reader that reads without moving focus does not hold it at all. Without the control, a person on a phone can stop an autoplaying carousel only through the system’s reduced-motion setting. Hide it only where your product gives another way to stop the motion, such as a pause for all moving content on the page (WCAG 2.2.2).

The previous and next controls

A row with no scroll bar gives a mouse no single press that moves it: only Shift with the wheel, or the dots where they are drawn. So the carousel draws a previous and a next control over the ends of its row. They are icon-only Buttons with chevrons, in the variant the design system names (elevated in the default system), and each moves the row one item back or on, as the dots and the arrow keys do.

navigation Drawn Shown
auto (the default) Where the primary pointer is a mouse or a trackpad, which can hover While the pointer is over the carousel or focus is in it
always On every device, touch included At all times
none Never Never
  • Why not on touch by default. A finger swipes the row, and on a phone the controls would stand over the items for good. Choose always where your people need them on touch too.
  • At the ends. Without loop, the previous control is disabled at the first item and the next at the last. A disabled control keeps focus and its place in the Tab order, so pressing next again never drops focus. With loop they go round.
  • Presses add up. A press while the row is moving counts from where it is going, so two quick presses move two items.
  • Autoplay. A press is the person’s own move: the interval starts again once the row is at rest. While the pointer is over the controls, or focus is on them, autoplay holds, as it does anywhere in the carousel.
  • Names. previousLabel and nextLabel name them for assistive technology, such as “Previous walk” and “Next walk”. Debug builds report a missing one.

Keep auto wherever you can. Choose none only where your page gives a mouse another way to move the row, such as the dots.

Items and their content

  • Content is laid out at the hero’s width. Every item lays its content out at the hero’s width, so a narrowed item shows the middle of its image, or the side nearest the hero with contentAlignment toward-hero, and the image glides inside the item as it grows and shrinks. Give an image that reads well from the part that shows.
  • No text on the item. The item draws no caption, because text over an image cannot be held to any contrast. Put a caption in your content over a scrim of your own, or show it outside the carousel.
  • One action per item. An item opens what it shows. Keep buttons, links and other controls out of its content.
  • No disabled item. A row to browse has nothing that is shown but unavailable. Leave such an item out.
  • Empty items are still seen. The item’s container is filled under its content with its resting color, whatever the item’s state, so an item whose image has not loaded yet is still visible.
  • States show over the content. Hover, focus and press are drawn as a layer over the content, with the ripple in that same layer, so they show on any image.

Scrolling and settling

People scroll the row by touch, pen, trackpad, a horizontal wheel, or Shift with a vertical wheel, and move it one item at a time with the previous and next controls. With snap, the row settles at a whole item when the scroll ends: a fling moves on to the next item in its direction, and a slower release goes to the nearest. A fling is a release faster than the platform’s minimum fling velocity, or 0.5 points per millisecond where the platform names none. Without loop, at the end of the range the last item is the hero, and the slots after it stay empty. With loop, each item is drawn once, in whichever place around the hero it falls, and the row goes round without end. Where motion is reduced, every movement the carousel starts itself happens at once.

When the carousel’s width or its items change, it arranges its slots again and keeps the item that was in focus where it was, without motion.

  • Label every item with what its content shows, in your product’s language.
  • Choose itemWidth to fit the content’s shape.
  • Give the carousel a label that names the row, such as “Recently played”.
  • Keep the playback control whenever the carousel advances by itself, and give it a playLabel and a pauseLabel.

Don’t

  • Don’t put controls inside an item’s content. The item is already a button.
  • Don’t use a carousel for content people must see all of, such as steps or terms. Items out of view are easy to miss.
  • Don’t turn on autoplay for a long row to browse. It suits a short featured row, with dots.
  • Don’t hide the playback control unless your product offers another way to stop the motion.

Accessibility

Role
list
Labeling
The items are a list named by label. Each item is one button named by its label, with its position and the number of items; its content is not read. The indicator is one slider named by label, whose value text is the current item's label. The playback control is a button named by pauseLabel while playing and by playLabel while paused. Items out of view are still reachable, and focusing one scrolls it into place. The previous and next controls are buttons named by previousLabel and nextLabel, disabled at the ends of a row that does not loop.
Minimum target
The hit area meets the minimum target size even when the visual size is smaller. minimum 32px · pointer 44px · spacing 8px · touch 48px

Keyboard

Keys Action
Tab / Shift+Tab Moves through the carousel's stops: the playback control (while it is drawn), the previous and next controls (while they are drawn), then the items as one stop (the item that last had focus, or else the resting item), then the indicator (while it is drawn), and on out (CRL-17).
Right Arrow / Left Arrow On an item: moves focus to the next or previous item and brings it into place. On the indicator: moves the row to the next or previous position. Both wrap only while the carousel loops, and are mirrored in right-to-left layouts.
Home / End On an item: moves focus to the first or last item and brings it into place. On the indicator: moves the row to the first or last position.
Enter / Space On an item: activates it (its click). On the playback control: pauses or plays autoplay. On the previous or the next control: moves the row back or on by one position (CRL-43).

Notes

  • Scrolling is never the only way to reach an item (WCAG 2.5.7, 2.1.1): the previous and next controls move the row one position with a single press of a mouse — drawn by default wherever the primary pointer is fine and can hover —, and the arrow keys, the indicator and screen-reader focus move through every item and bring it into place. The row draws no scroll bar, so without the controls a mouse could move the row only with Shift and the wheel.
  • Where the previous and next controls are, and when. They stand over the ends of the row, as the arrows of Ant Design's and Mantine's carousels and the overlay layouts of Fluent 2's do, not in the controls row, which exists only for a featured row with dots or autoplay. By default (auto) they are drawn only for a pointer that is fine and can hover, and shown while it is over the carousel or focus is within it: a touch screen moves the row with the finger's own swipe, and there the controls would stand over the items for good. A product whose people need them on touch as well sets always. Their place in the Tab sequence is the WAI-ARIA carousel example's: the playback control, then previous and next, then the slides.
  • A previous or next control at the end of a row that does not loop is disabled but keeps focus and its place in the Tab order (the Button's focusableWhenDisabled), so that pressing next again and again never drops focus to the page, and the number of stops does not change with the scroll.
  • An item entering or leaving at an edge of a row with fluid widths is, between resting positions, narrower than a touch target (CRL-4, CRL-12). A row that snaps never rests there; a row that does not snap can, and the arrow keys, the indicator and a further scroll all bring that item to a slot, where it has its whole target.
  • Autoplay (WCAG 2.2.2 Pause, Stop, Hide). A carousel that advances by itself holds while it is hovered, while focus is anywhere in it, while it is pressed and while it is hidden, and it never advances where the platform's reduced-motion setting is on (CRL-33, CRL-34). While autoplay is on, the playback control is drawn by default and is the first Tab stop, so a keyboard user reaches it before the items (CRL-17).
  • Keep playback controllable. A product may hide the playback control (playbackControl false), but it should keep it wherever it can. The holds are not a way to stop the motion: on touch there is no hover, a finger on the carousel holds it only while it stays there, and a screen reader that reads without moving focus does not hold it at all. Without the control, a person on a phone can stop an autoplaying carousel only through the system's reduced-motion setting. Hide it only where the product gives the person another way to stop the motion, such as a pause for all moving content on the page.
  • Autoplay makes no announcement and never moves focus (CRL-32). A person who wants to know what changed finds the current item as the indicator's value.
  • Loop keeps the arrow keys and the indicator going round, but Home and End still go to the first and last item, so a person can always find the ends of an endless row.
  • The indicator is one slider, not a row of unlabelled buttons: one Tab stop, the arrow keys to move, the current item's label as its value. Its hit area is the whole container and the controls row's height, so the dots need no target of their own.
  • The current dot is told apart by its stretched shape, not by color alone (WCAG 1.4.1), and the other dots use the functional outline role (3:1 against the surface).
  • Web: the host has no role; a shadow element with role list, named by label, holds the item slot, so the slotted `<tanrei-carousel-item>` elements (role listitem, around a shadow element with role button and tabindex, roving: 0 on the Tab stop, -1 on the others) are its items, as the interactive card draws its button. The indicator is a shadow element with role slider and tabindex 0, and the playback control a native `<button>`; both sit after the list, outside it. Compose has no list role: the row gives `collectionInfo` and each item `collectionItemInfo` with `Role.Button`; the indicator is a `progressBarRangeInfo` with `setProgress`. Flutter reads each item's position through `IndexedSemantics`, and the indicator is a `Semantics(slider: true)` with increase and decrease actions. SwiftUI's indicator is `accessibilityAdjustableAction`, React Native's the adjustable role with increment and decrement actions. SwiftUI and React Native have no position-in-set property for a custom container, so there the screen reader's own count of the items stands in for CRL-19's position and number; their READMEs say so.
  • How a state looks is a value decision of the active design system; components read the state's tokens and never compute the effect themselves.

Generated from specs/carousel.spec.json, tokens/sys/measure.tokens.json

What the component handles

  • The carousel is a list named by label. Each item is one button named by its label, with its position among the items and their number. Its content is hidden from assistive technology.
  • Items out of view stay exposed, in order, so a screen reader reaches every one. Moving screen-reader focus to an item scrolls it into place.
  • Tab stops. The carousel has up to five: the playback control, while it is drawn; the previous and next controls, while they are drawn; the items, as one stop; and the dots, while they are drawn. The playback control comes first, before the items, so a keyboard user can stop the motion before reaching anything else. The previous and next controls come before the items, as in the WAI-ARIA carousel example. The items are entered at the one that last had keyboard focus, or else at the item resting in the hero’s place.
  • Right Arrow and Left Arrow move focus to the next and previous item. They stop at the ends, and wrap only while the carousel loops. Home and End move to the first and last item, even in a row that loops. In a right-to-left layout, Left Arrow moves to the next item.
  • Moving focus brings the focused item into the hero’s place, as near as the end of the range allows, and the shorter way round in a row that loops. In a row with fixed widths and free scroll at the start, it just brings the item wholly into view.
  • Enter and Space activate the focused item. A press that turns into a scroll does not activate the item it started on.
  • The dots are one slider named by label, whose value is the current item’s label. The arrow keys, Home and End, and the platform’s increment and decrement move the row one position. The current dot is told apart by its stretched shape, not by color alone.
  • The playback control is a button named by pauseLabel while playing and playLabel while paused. It has no pressed state, so it never reads as “Pause, pressed”. Activating it keeps focus on it. Its pause and play glyphs are not mirrored, and before the icon font has loaded no glyph’s name is drawn as text.
  • The previous and next controls are buttons named by previousLabel and nextLabel. Activating one keeps focus on it. At the ends of a row that does not loop the control is disabled, but it keeps focus and stays in the Tab order. Hidden under auto, they are still reached by Tab and read by a screen reader, and focus shows them. Their chevrons are mirrored in a right-to-left layout where the icon set says so, and the previous control is then at the right.
  • Autoplay holds while focus is anywhere in the carousel, never moves focus and announces nothing, and never runs where motion is reduced.
  • The focus ring is drawn inside the item, where the row cannot clip it, and around the dots and the playback control. It shows for keyboard focus only.
  • Each item’s hit area is its container plus half the gap on each side, and never less than the minimum target, even for a small item. An item that is still entering or leaving at the edge is narrower than that, and its hit area never covers its neighbour’s. The playback control’s hit area is the touch target, and the dots’ is their whole container and the row’s height.
  • Scrolling is never the only way to reach an item: the previous and next controls move the row with a single press of a mouse (WCAG 2.5.7), and the arrow keys, the dots and screen-reader focus reach every one.
  • The carousel keeps its height and items at larger text sizes. It holds no text of its own, and your content follows the text size itself.
  • Debug builds report an item without a label, a carousel without a label, a playback control without playLabel or pauseLabel, previous and next controls without previousLabel or nextLabel, dots that do not fit, an unknown heroAlignment, contentAlignment or navigation, and an itemWidth or an autoplayInterval that is not a positive number. The web also reports an interactive element inside an item’s content.

Known platform gaps:

  • SwiftUI and React Native have no position-in-set property for a custom container, so the screen reader’s own count of the items stands in for each item’s position and the number of items. SwiftUI has no list role either: the carousel is a container named by label.
  • Compose has no list role. The row gives its collection size and each item its position, with the button role, so TalkBack announces a collection rather than a list.
  • Only the web can inspect an item’s content, so only the web reports a control inside it. On the other platforms the rule is yours to keep.
  • Web: the Tab stop moves to any item that takes focus, a click’s included, where the spec names the item that last had keyboard focus. A pen flick settles at the nearest item, not the next one. A screen reader’s virtual cursor that does not move focus scrolls the row as the browser does, without bringing the item to the hero’s place.
  • SwiftUI: the carousel is always as tall as its height token, because SwiftUI cannot tell a frame from a stack’s proposal. Size it through a layer’s tokens. The settle moves with the scroll view’s own deceleration, not the carousel’s scroll motion, and not at once where motion is reduced. It builds every item and places each again on every scroll frame. The arrow keys, the Tab stop and VoiceOver focus are tested as rules, not with a keyboard or VoiceOver on a device.
  • Compose composes and lays out every item, including the ones out of view. A wheel, which does not fling, settles at the nearest item. The scroll is verified under Robolectric only, not on a device.
  • Flutter settles a carousel that snaps after every mouse-wheel event, not when the wheel gesture ends. It has not yet been checked with TalkBack and VoiceOver on a device.
  • React Native re-lays out every item on the JavaScript thread on every scroll frame, and renders every item. The arrow keys work only where a hardware keyboard’s events reach the app. The scroll-driven placement, the settle, right-to-left and screen-reader focus are verified in Jest only, never on a device.
  • Under m3-like, items keep the default fill where Material’s carousel uses the surface color, on purpose, so an item whose image has not loaded is still seen.

What you need to do

  • Give the carousel a label, and every item a label that says what its content shows. The content is not read.
  • With autoplay, give the playback control a playLabel and a pauseLabel that say what it does, and keep it drawn.
  • Give the previous and next controls a previousLabel and a nextLabel, and keep navigation at auto unless your page gives a mouse another way to move the row.
  • Keep controls out of items’ content.
  • If the content carries meaning its label does not, such as a price on a poster, put that in the label.
  • On SwiftUI, Compose and React Native, keep the number of items modest: the carousel there builds every item, including the ones out of view.