Carousel
Carousel lets people browse a long row of items that scrolls sideways, with a button at each end.
<Carousel aria-label="Covers"> <CarouselRail fade> <Flex gap="4"> <CarouselItem>…</CarouselItem> <CarouselItem>…</CarouselItem> </Flex> </CarouselRail> <CarouselPrevious>‹</CarouselPrevious> <CarouselNext>›</CarouselNext></Carousel>A Carousel shows a row of items that scrolls sideways and comes to rest on an item each time. Use it for a long row of peers that people browse, such as templates, recent projects or covers. When every item fits in the space, use a Grid or a Flex, and for a vertical list that scrolls, use a ScrollArea.
Put a CarouselRail inside the Carousel, and wrap each item the rail should stop on in a CarouselItem. The component doesn't set a width, a gap or an aspect ratio for the items, so set the item width yourself and place the items in a Flex to space them. Give the rail a bounded width, and set fade when it runs to the edge of a pane.
Place CarouselPrevious and CarouselNext anywhere inside the Carousel, either in a row above the rail or on each side of it. The package ships no icons, so put your own arrows in the buttons. No scrollbar is drawn, because the buttons and the fade already show that there is more to see.
Scrolling is the browser's own, so the mouse wheel, the trackpad, touch and the keyboard all work as usual. Each button press moves the rail by one item, and a button is disabled when there is nothing more in its direction. The carousel never plays on its own and never loops.
A Carousel renders a group that screen readers announce as a carousel. Name it with aria-label, or point aria-labelledby at the heading above it. The buttons are named "Previous" and "Next" by default and tell assistive technology which rail they move. A disabled button stays focusable, so keyboard focus isn't lost when the rail reaches an end. On a right-to-left page, the rail starts on the right.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Naming the carousel
Carousel
Carousel lets people browse a long row of items that scrolls sideways, with a button at each end.
| Prop | Type | What it does |
|---|---|---|
aria-label? | string | The name of the carousel for screen readers. |
aria-labelledby? | string | The id of an element on the page that names the carousel, usually the heading above it. |
children? | React.ReactNode | The rail and its buttons. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
The scrolling row
CarouselRail
The row that scrolls. It is a ScrollArea whose scrolling comes to rest on items. Give it a bounded width, and set fade when it runs to the edge of a pane
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The items. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
fade? | boolean | Fades the content at an edge when more content is past that edge. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
- Autoplay — Content that moves on a timer makes people lose their place, so the rail moves only when someone scrolls it or presses a button.
- Looping — A loop needs cloned items or a fake scroll position. With real ends, a disabled button tells people they have reached the last item.
- Drag to scroll — Touch and trackpads already drag the rail. With a mouse, dragging would get in the way of selecting text and dragging images.
- A width, a gap or an aspect ratio for the items — Every carousel lays out its items differently, so you set the item size yourself and use a Flex for the gap. The component only marks where scrolling comes to rest.
orientation— A carousel always scrolls sideways. For a vertical list that scrolls, use a ScrollArea.- Dots under the rail — Dots repeat what the rail already shows, each one needs its own accessible name, and people can't count them once there are more than a few.