Skip to content

Carousel

Download .md

A carousel shows a row of cards that people slide through, such as the latest releases or highlights on a home screen.

  • Use it for content that people may skip, such as releases or highlights.
  • Never put required information in it: what sits off screen may never be seen.
  • Never autoplay.
  • Show the edge of the next card, so people can tell there is more.
React

Senja di Kota

Rara Senandika

Kaset Pertama

Bima Laras

Pulang Sore

Nada Kirana

Hujan Bulan Juni

Arka Wening

Lampu Kota

Sinta Maharani

Vue

Senja di Kota

Rara Senandika

Kaset Pertama

Bima Laras

Pulang Sore

Nada Kirana

Hujan Bulan Juni

Arka Wening

Lampu Kota

Sinta Maharani

123
  1. 1Current slide
  2. 2Next slide, partly shown
  3. 3Position dots

Cards in a row, 16px apart, with square outline previous and next buttons (not pills) that turn off at the ends. On phones the buttons hide and people swipe; the page never scrolls sideways.

On phones, CarouselDots under the row may show where people are, since they swipe and see no buttons:

  • One dot per stop: 6px, radius-full, 4px apart, centered 12px under the cards.
  • The current slide’s dot is 20px wide in primary; the others are input.
  • Use dots for up to 5 slides. With more, leave them out.
  • Dots only show the position. They are not buttons, and screen readers skip them.
React Vue Flutter Type Default Use
opts :opts PageController(viewportFraction: 0.85) Embla options none Such as { align: "start" }.
CarouselItem aria-label same Semantics label text none The slide’s position, such as “1 dari 5”.
CarouselPrevious label, CarouselNext label same Semantics label text Previous slide, Next slide The buttons’ names, such as “Sebelumnya”.
CarouselDots max CarouselDots :max dots row (see the Flutter code) number 5 Position dots for phones; with more stops than this they don’t show.
setApi @init-api the controller function none Reads or moves the carousel from outside.
import { MusicIcon } from "lucide-react"
import { Carousel, CarouselContent, CarouselDots, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"
const releases = [
{ title: "Senja di Kota", artist: "Rara Senandika" },
{ title: "Kaset Pertama", artist: "Bima Laras" },
{ title: "Pulang Sore", artist: "Nada Kirana" },
{ title: "Hujan Bulan Juni", artist: "Arka Wening" },
{ title: "Lampu Kota", artist: "Sinta Maharani" },
]
export default function CarouselDemo() {
return (
<Carousel aria-label="Rilis terbaru" opts={{ align: "start" }} className="w-full max-w-md sm:mx-12">
<CarouselContent>
{releases.map((r, i) => (
<CarouselItem key={r.title} aria-label={`${i + 1} dari ${releases.length}`} className="basis-2/3 sm:basis-1/2">
<div className="flex flex-col gap-2">
<div className="flex aspect-square items-center justify-center rounded-lg bg-muted">
<MusicIcon aria-hidden="true" className="size-6 text-muted-foreground" />
</div>
<div className="text-sm">
<p className="truncate font-medium">{r.title}</p>
<p className="truncate text-muted-foreground">{r.artist}</p>
</div>
</div>
</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious label="Sebelumnya" />
<CarouselNext label="Berikutnya" />
<CarouselDots />
</Carousel>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/carousel.json
  • The carousel is a region with aria-roledescription="carousel"; give it a name, such as “Rilis terbaru”.
  • Each slide is a group with aria-roledescription="slide" and a label such as “1 dari 5”.
  • The previous and next buttons are named and turn off at the ends.
  • Dots are aria-hidden; the slide labels, such as “1 dari 3”, carry the position.
  • Left and right arrow keys move between slides while focus is inside.