# Carousel

> Page through a row of related slides with buttons, keys, or a swipe.

Source: https://www.honestui.com/docs/components/carousel

```tsx
import {
  Card,
  CardDescription,
  CardHeader,
  CardPanel,
  CardTitle,
} from "@/components/honest-ui/ui/card"
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/honest-ui/ui/carousel"

const releases = [
  {
    version: "v2.4",
    title: "Density tokens",
    description: "Compact, default, and comfortable spacing from one attribute.",
    detail: "Tables, menus, and forms read the same density so a dense screen stays consistent.",
  },
  {
    version: "v2.3",
    title: "Paste table",
    description: "Paste rows from a spreadsheet and review them before import.",
    detail: "Every cell is validated in place, with the failing rows kept for correction.",
  },
  {
    version: "v2.2",
    title: "Change review",
    description: "Show what an edit changes before anyone confirms it.",
    detail: "Field-level diffs with an audit trail of who approved each change.",
  },
  {
    version: "v2.1",
    title: "Async action",
    description: "Buttons that report pending, success, failure, and undo.",
    detail: "The label tells people what happened instead of a spinner that never explains.",
  },
]

export function CarouselDemo() {
  return (
    <Carousel aria-label="Recent releases" className="w-full max-w-sm">
      <CarouselContent>
        {releases.map((release) => (
          <CarouselItem key={release.version}>
            <Card className="h-full">
              <CardHeader>
                <p className="text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] tabular-nums">
                  {release.version}
                </p>
                <CardTitle>{release.title}</CardTitle>
                <CardDescription>{release.description}</CardDescription>
              </CardHeader>
              <CardPanel className="text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-control,13px)] [line-height:var(--hui-line-height-regular)]">
                {release.detail}
              </CardPanel>
            </Card>
          </CarouselItem>
        ))}
      </CarouselContent>
      <div className="mt-[var(--hui-space-4)] flex justify-end gap-[var(--hui-space-2)]">
        <CarouselPrevious />
        <CarouselNext />
      </div>
    </Carousel>
  )
}

```

## Overview [#overview]

Use Carousel when a set of peers shares one slot and people browse it in order: release notes, template thumbnails, onboarding steps, product photos. Each slide should make sense on its own, because most people will only see the first one or two. If everything in the set is equally important, a grid or a list shows it all at once and is usually the better choice.

Carousel has no dependency. Paging comes from native CSS scroll snapping, so touch swipes, trackpad gestures, and the mouse wheel behave the way the platform already does, and the component only adds buttons, keys, position tracking, and labels on top.

## Anatomy [#anatomy]

`Carousel` is the labelled region that holds state. `CarouselContent` is the scroll-snapping viewport, and each `CarouselItem` is one slide. `CarouselPrevious` and `CarouselNext` page one slide at a time, and `CarouselDots` jumps straight to a slide. The controls can sit anywhere inside `Carousel`, above, below, or beside the viewport.

## Sizing slides [#sizing-slides]

A slide fills the viewport by default (`basis-full`). Set a basis on `CarouselItem` to show several at once, such as `basis-1/2 md:basis-1/3`, and set `--hui-carousel-gap` on `CarouselContent` to change the space between slides. A vertical carousel needs an explicit height on `CarouselContent`, because the viewport scrolls inside it.

## Accessibility [#accessibility]

The root is a `region` with `aria-roledescription="carousel"`, and its `aria-label` is required so the landmark has a name. Each slide is a `group` with `aria-roledescription="slide"` and an automatic label such as "3 of 8"; pass your own `aria-label` when a title says more.

When focus is inside the carousel, Left and Right Arrow move one slide (Up and Down in a vertical carousel), and the directions flip in right-to-left layouts. Arrow keys inside text fields, selects, and sliders are left alone. A polite live region announces the new position after each move. The buttons are disabled at the ends unless `loop` is set, and smooth scrolling is turned off when people prefer reduced motion. Carousel never advances on its own: auto-rotation moves content away from people who are still reading it.

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;carousel&#x22;]" />
  

  
    
      
        Install the 

        [Button](/docs/components/button)

         component.
      

      
        Copy and paste the following code into your project.
      

      ### components/ui/carousel.tsx

```tsx
"use client"

import * as React from "react"
import {
  ChevronDown as ChevronDownIcon,
  ChevronLeft as ChevronLeftIcon,
  ChevronRight as ChevronRightIcon,
  ChevronUp as ChevronUpIcon,
} from "honestui/icons"

import { cn } from "@/lib/utils"
import { Button } from "@/components/honest-ui/ui/button"

type CarouselOrientation = "horizontal" | "vertical"

type CarouselApi = {
  /** Index of the slide aligned to the start edge. */
  index: number
  /** Number of slides. */
  count: number
  canScrollPrev: boolean
  canScrollNext: boolean
  scrollTo: (index: number) => void
  scrollPrev: () => void
  scrollNext: () => void
}

type CarouselContextValue = CarouselApi & {
  orientation: CarouselOrientation
  viewportRef: React.RefCallback<HTMLDivElement>
  registerItem: (node: HTMLElement) => () => void
  items: HTMLElement[]
}

const CarouselContext = React.createContext<CarouselContextValue | null>(null)

function useCarousel() {
  const context = React.useContext(CarouselContext)
  if (!context) {
    throw new Error("useCarousel must be used within a <Carousel />")
  }
  return context
}

function prefersReducedMotion() {
  return (
    typeof window !== "undefined" &&
    window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
  )
}

type CarouselProps = Omit<React.ComponentProps<"div">, "aria-label"> & {
  /** Names the carousel for assistive technology, such as "Featured templates". */
  "aria-label": string
  orientation?: CarouselOrientation
  /** Wrap from the last slide to the first, and back, with the buttons and keys. */
  loop?: boolean
  /** Receives the carousel API whenever its state changes. */
  setApi?: (api: CarouselApi) => void
  onIndexChange?: (index: number) => void
}

function Carousel({
  orientation = "horizontal",
  loop = false,
  setApi,
  onIndexChange,
  className,
  children,
  onKeyDown,
  ...props
}: CarouselProps) {
  const [viewport, setViewport] = React.useState<HTMLDivElement | null>(null)
  const [items, setItems] = React.useState<HTMLElement[]>([])
  const [index, setIndex] = React.useState(0)
  const [edges, setEdges] = React.useState({ atStart: true, atEnd: true })
  const vertical = orientation === "vertical"

  // Items register in document order so labels and dots stay correct when
  // slides are added or removed.
  const registerItem = React.useCallback((node: HTMLElement) => {
    setItems((current) =>
      [...current, node].sort((a, b) =>
        a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
      )
    )
    return () => setItems((current) => current.filter((item) => item !== node))
  }, [])

  // Reads the scroll position once per frame. The active slide is the one
  // whose start edge is closest to the viewport's start edge, which also
  // works for several slides per view and for RTL, where scrollLeft is
  // negative.
  React.useEffect(() => {
    if (!viewport) return
    let frame = 0
    const measure = () => {
      frame = 0
      const rtl = !vertical && getComputedStyle(viewport).direction === "rtl"
      const scroll = vertical ? viewport.scrollTop : Math.abs(viewport.scrollLeft)
      const max = vertical
        ? viewport.scrollHeight - viewport.clientHeight
        : viewport.scrollWidth - viewport.clientWidth
      setEdges({ atStart: scroll <= 1, atEnd: scroll >= max - 1 })

      if (items.length === 0) return
      const box = viewport.getBoundingClientRect()
      let closest = 0
      let closestDistance = Infinity
      items.forEach((item, itemIndex) => {
        const rect = item.getBoundingClientRect()
        const distance = vertical
          ? Math.abs(rect.top - box.top)
          : rtl
            ? Math.abs(rect.right - box.right)
            : Math.abs(rect.left - box.left)
        if (distance < closestDistance) {
          closestDistance = distance
          closest = itemIndex
        }
      })
      // At the end edge the last slide may never reach the start edge when
      // several slides share the view, so the last one counts as active.
      setIndex(scroll >= max - 1 && max > 0 ? items.length - 1 : closest)
    }
    const schedule = () => {
      if (!frame) frame = requestAnimationFrame(measure)
    }
    measure()
    viewport.addEventListener("scroll", schedule, { passive: true })
    const resizeObserver = new ResizeObserver(schedule)
    resizeObserver.observe(viewport)
    return () => {
      cancelAnimationFrame(frame)
      viewport.removeEventListener("scroll", schedule)
      resizeObserver.disconnect()
    }
  }, [viewport, items, vertical])

  const scrollTo = React.useCallback(
    (target: number) => {
      if (!viewport || items.length === 0) return
      const clamped = Math.max(0, Math.min(items.length - 1, target))
      const item = items[clamped]
      const box = viewport.getBoundingClientRect()
      const rect = item.getBoundingClientRect()
      const behavior: ScrollBehavior = prefersReducedMotion() ? "auto" : "smooth"
      if (vertical) {
        viewport.scrollBy({ top: rect.top - box.top, behavior })
      } else {
        const rtl = getComputedStyle(viewport).direction === "rtl"
        viewport.scrollBy({
          left: rtl ? rect.right - box.right : rect.left - box.left,
          behavior,
        })
      }
    },
    [viewport, items, vertical]
  )

  const count = items.length
  const canScrollPrev = loop ? count > 1 : !edges.atStart
  const canScrollNext = loop ? count > 1 : !edges.atEnd

  const scrollPrev = React.useCallback(() => {
    if (loop && edges.atStart) scrollTo(count - 1)
    else scrollTo(index - 1)
  }, [loop, edges.atStart, scrollTo, count, index])

  const scrollNext = React.useCallback(() => {
    if (loop && edges.atEnd) scrollTo(0)
    else scrollTo(index + 1)
  }, [loop, edges.atEnd, scrollTo, index])

  const api = React.useMemo<CarouselApi>(
    () => ({ index, count, canScrollPrev, canScrollNext, scrollTo, scrollPrev, scrollNext }),
    [index, count, canScrollPrev, canScrollNext, scrollTo, scrollPrev, scrollNext]
  )

  React.useEffect(() => {
    setApi?.(api)
  }, [api, setApi])

  const lastReportedIndex = React.useRef(index)
  React.useEffect(() => {
    if (lastReportedIndex.current === index) return
    lastReportedIndex.current = index
    onIndexChange?.(index)
  }, [index, onIndexChange])

  const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
    onKeyDown?.(event)
    if (event.defaultPrevented) return
    // Typing in a field inside a slide keeps its own arrow keys.
    const target = event.target as HTMLElement
    if (target.closest("input, textarea, select, [contenteditable='true'], [role='slider']")) {
      return
    }
    const rtl = !vertical && getComputedStyle(event.currentTarget).direction === "rtl"
    const prevKey = vertical ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft"
    const nextKey = vertical ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight"
    if (event.key === prevKey) {
      event.preventDefault()
      scrollPrev()
    } else if (event.key === nextKey) {
      event.preventDefault()
      scrollNext()
    }
  }

  return (
    <CarouselContext.Provider
      value={{ ...api, orientation, viewportRef: setViewport, registerItem, items }}
    >
      <div
        role="region"
        aria-roledescription="carousel"
        data-slot="carousel"
        data-orientation={orientation}
        className={cn("relative", className)}
        onKeyDown={handleKeyDown}
        {...props}
      >
        {children}
        {/* Announces the new position after a button, key, or swipe moves
            the carousel. It is polite, so it waits for the user to pause. */}
        <span data-slot="carousel-status" aria-live="polite" aria-atomic="true" className="sr-only">
          {count > 0 ? `Slide ${index + 1} of ${count}` : ""}
        </span>
      </div>
    </CarouselContext.Provider>
  )
}

function CarouselContent({
  className,
  children,
  ...props
}: React.ComponentProps<"div">) {
  const { viewportRef, orientation } = useCarousel()
  const vertical = orientation === "vertical"

  return (
    <div
      ref={viewportRef}
      data-slot="carousel-content"
      data-orientation={orientation}
      className={cn(
        // Native scroll snapping does the paging, so touch, trackpad, and
        // wheel gestures behave like the platform without a script.
        // The scrollbar is hidden with !important because apps often style
        // `* { scrollbar-width }` outside a cascade layer, which beats utilities.
        "flex gap-[var(--hui-carousel-gap,var(--hui-space-4))] overscroll-contain [scrollbar-width:none]! [&::-webkit-scrollbar]:hidden! motion-safe:scroll-smooth focus-visible:[outline:var(--hui-focus-ring)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-accent)] rounded-[var(--hui-radius-2)]",
        vertical
          ? "h-full flex-col overflow-y-auto overflow-x-hidden snap-y snap-mandatory"
          : "overflow-x-auto overflow-y-hidden snap-x snap-mandatory",
        className
      )}
      {...props}
    >
      {children}
    </div>
  )
}

function CarouselItem({
  className,
  "aria-label": ariaLabel,
  ...props
}: React.ComponentProps<"div">) {
  const { registerItem, items, count } = useCarousel()
  const [node, setNode] = React.useState<HTMLDivElement | null>(null)

  React.useEffect(() => {
    if (!node) return
    return registerItem(node)
  }, [node, registerItem])

  const position = node ? items.indexOf(node) + 1 : 0

  return (
    <div
      ref={setNode}
      role="group"
      aria-roledescription="slide"
      aria-label={ariaLabel ?? (position > 0 ? `${position} of ${count}` : undefined)}
      data-slot="carousel-item"
      className={cn("min-w-0 shrink-0 grow-0 basis-full snap-start", className)}
      {...props}
    />
  )
}

type CarouselButtonProps = React.ComponentProps<typeof Button>

function CarouselPrevious({
  className,
  variant = "outline",
  size = "icon-sm",
  onClick,
  ...props
}: CarouselButtonProps) {
  const { orientation, canScrollPrev, scrollPrev } = useCarousel()

  return (
    <Button
      data-slot="carousel-previous"
      variant={variant}
      size={size}
      disabled={!canScrollPrev}
      aria-label="Previous slide"
      className={cn("rounded-full", className)}
      onClick={(event) => {
        onClick?.(event)
        if (!event.defaultPrevented) scrollPrev()
      }}
      {...props}
    >
      {orientation === "vertical" ? (
        <ChevronUpIcon aria-hidden="true" />
      ) : (
        <ChevronLeftIcon aria-hidden="true" className="rtl:rotate-180" />
      )}
    </Button>
  )
}

function CarouselNext({
  className,
  variant = "outline",
  size = "icon-sm",
  onClick,
  ...props
}: CarouselButtonProps) {
  const { orientation, canScrollNext, scrollNext } = useCarousel()

  return (
    <Button
      data-slot="carousel-next"
      variant={variant}
      size={size}
      disabled={!canScrollNext}
      aria-label="Next slide"
      className={cn("rounded-full", className)}
      onClick={(event) => {
        onClick?.(event)
        if (!event.defaultPrevented) scrollNext()
      }}
      {...props}
    >
      {orientation === "vertical" ? (
        <ChevronDownIcon aria-hidden="true" />
      ) : (
        <ChevronRightIcon aria-hidden="true" className="rtl:rotate-180" />
      )}
    </Button>
  )
}

function CarouselDots({ className, ...props }: React.ComponentProps<"div">) {
  const { count, index, scrollTo, orientation } = useCarousel()

  return (
    <div
      data-slot="carousel-dots"
      className={cn(
        "flex items-center justify-center gap-[var(--hui-space-1)]",
        orientation === "vertical" && "flex-col",
        className
      )}
      {...props}
    >
      {Array.from({ length: count }, (_, dotIndex) => {
        const active = dotIndex === index
        return (
          <button
            key={dotIndex}
            type="button"
            data-slot="carousel-dot"
            data-active={active ? "" : undefined}
            aria-label={`Go to slide ${dotIndex + 1}`}
            aria-current={active ? "true" : undefined}
            onClick={() => scrollTo(dotIndex)}
            className="group relative inline-flex size-[var(--hui-space-5)] cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 outline-none focus-visible:[outline:var(--hui-focus-ring)] focus-visible:outline-offset-[-2px] pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-6"
          >
            <span
              aria-hidden="true"
              className="block size-1.5 rounded-full bg-[var(--hui-color-foreground-base-tertiary)] motion-safe:[transition:background-color_var(--hui-duration-fast)_var(--hui-ease-out),width_var(--hui-duration-fast)_var(--hui-ease-out)] group-hover:bg-[var(--hui-color-foreground-base-secondary)] group-data-active:w-3.5 group-data-active:bg-[var(--hui-color-foreground-base-primary)] forced-colors:bg-[GrayText] forced-colors:group-data-active:bg-[Highlight]"
            />
          </button>
        )
      })}
    </div>
  )
}

export {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselPrevious,
  CarouselNext,
  CarouselDots,
  useCarousel,
  type CarouselApi,
  type CarouselProps,
}

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import {
  Carousel,
  CarouselContent,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"
```

```tsx
<Carousel aria-label="Recent releases">
  <CarouselContent>
    <CarouselItem>...</CarouselItem>
    <CarouselItem>...</CarouselItem>
    <CarouselItem>...</CarouselItem>
  </CarouselContent>
  <CarouselPrevious />
  <CarouselNext />
</Carousel>
```

Read the position with `setApi` or `onIndexChange` to render a counter or sync another view:

```tsx
const [api, setApi] = React.useState<CarouselApi | null>(null)

<Carousel aria-label="Steps" setApi={setApi}>
  ...
  <p>{api ? `${api.index + 1} / ${api.count}` : null}</p>
</Carousel>
```

## Don't do this [#dont-do-this]

### Hiding required content in later slides [#hiding-required-content-in-later-slides]

```tsx
// Bad
<Carousel aria-label="Plan details">
  <CarouselContent>
    <CarouselItem>Price</CarouselItem>
    <CarouselItem>Cancellation terms</CarouselItem>
  </CarouselContent>
</Carousel>
```

Few people page past the first slide. Anything someone must read before deciding, such as terms, limits, or prices, belongs on the page where it is always visible.

### An unnamed carousel [#an-unnamed-carousel]

```tsx
// Bad
<Carousel aria-label="">...</Carousel>
```

```tsx
// Good
<Carousel aria-label="Customer stories">...</Carousel>
```

A screen reader announces the region by its name. Without one, people hear "carousel" with no hint of what it holds.

## Examples [#examples]

### Several slides per view [#several-slides-per-view]

```tsx
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/honest-ui/ui/carousel"

const templates = [
  { name: "Invoice", rows: "12 fields" },
  { name: "Onboarding", rows: "8 steps" },
  { name: "Incident report", rows: "15 fields" },
  { name: "Expense claim", rows: "9 fields" },
  { name: "Access request", rows: "6 fields" },
  { name: "Vendor review", rows: "11 fields" },
  { name: "Release checklist", rows: "14 steps" },
]

export function CarouselMultiple() {
  return (
    <Carousel aria-label="Form templates" className="w-full max-w-xl">
      <div className="mb-[var(--hui-space-3)] flex items-center justify-between">
        <h3 className="m-0 text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-regular)] [font-weight:var(--hui-font-weight-medium)]">
          Templates
        </h3>
        <div className="flex gap-[var(--hui-space-2)]">
          <CarouselPrevious />
          <CarouselNext />
        </div>
      </div>
      <CarouselContent>
        {templates.map((template) => (
          <CarouselItem key={template.name} className="basis-1/2 md:basis-1/3">
            <div className="flex aspect-[4/3] flex-col justify-end rounded-[var(--hui-radius-2)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-secondary)] p-[var(--hui-space-4)]">
              <p className="m-0 text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-control,13px)] [font-weight:var(--hui-font-weight-medium)]">
                {template.name}
              </p>
              <p className="m-0 text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)]">
                {template.rows}
              </p>
            </div>
          </CarouselItem>
        ))}
      </CarouselContent>
    </Carousel>
  )
}

```

### Dots and counter [#dots-and-counter]

`CarouselDots` gives each slide a button, and `setApi` provides the numbers for a visible counter.

```tsx
"use client"

import * as React from "react"

import {
  Carousel,
  CarouselContent,
  CarouselDots,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
  type CarouselApi,
} from "@/components/honest-ui/ui/carousel"

const steps = [
  "Connect your data source",
  "Choose the columns to import",
  "Map columns to fields",
  "Review rows that failed validation",
  "Fix or skip each failing row",
  "Preview the final import",
  "Confirm and run the import",
  "Share the import report",
]

export function CarouselWithDots() {
  const [api, setApi] = React.useState<CarouselApi | null>(null)

  return (
    <Carousel aria-label="Import walkthrough" setApi={setApi} className="w-full max-w-sm">
      <CarouselContent>
        {steps.map((step, index) => (
          <CarouselItem key={step}>
            <div className="flex aspect-video flex-col justify-between rounded-[var(--hui-radius-3)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-secondary)] p-[var(--hui-space-5)]">
              <span className="text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] tabular-nums">
                Step {index + 1}
              </span>
              <p className="m-0 text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-large)] [font-weight:var(--hui-font-weight-medium)] [line-height:var(--hui-line-height-large)]">
                {step}
              </p>
            </div>
          </CarouselItem>
        ))}
      </CarouselContent>
      <div className="mt-[var(--hui-space-3)] flex items-center justify-between gap-[var(--hui-space-3)]">
        <CarouselPrevious />
        <div className="flex flex-col items-center gap-[var(--hui-space-1)]">
          <CarouselDots />
          <p
            aria-hidden="true"
            className="m-0 text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] tabular-nums"
          >
            {api ? `${api.index + 1} / ${api.count}` : `1 / ${steps.length}`}
          </p>
        </div>
        <CarouselNext />
      </div>
    </Carousel>
  )
}

```

### Vertical [#vertical]

```tsx
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/honest-ui/ui/carousel"

const updates = [
  { time: "09:12", text: "Deploy 4812 reached production in all regions." },
  { time: "09:40", text: "Error rate on checkout returned to its 7-day baseline." },
  { time: "10:05", text: "Invoices for March finished exporting to the warehouse." },
  { time: "10:31", text: "Two new members accepted their workspace invitations." },
  { time: "11:02", text: "Nightly backup verified with 0 missing objects." },
]

export function CarouselVertical() {
  return (
    <Carousel
      aria-label="Activity updates"
      orientation="vertical"
      className="flex w-full max-w-sm items-center gap-[var(--hui-space-3)]"
    >
      <CarouselContent className="h-28 flex-1">
        {updates.map((update) => (
          <CarouselItem key={update.time}>
            <div className="flex h-28 flex-col justify-center gap-[var(--hui-space-1)] rounded-[var(--hui-radius-2)] border-[0.5px] border-[var(--hui-color-border-base-primary)] px-[var(--hui-space-4)]">
              <span className="text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] tabular-nums">
                {update.time}
              </span>
              <p className="m-0 text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-control,13px)] [line-height:var(--hui-line-height-regular)]">
                {update.text}
              </p>
            </div>
          </CarouselItem>
        ))}
      </CarouselContent>
      <div className="flex flex-col gap-[var(--hui-space-2)]">
        <CarouselPrevious />
        <CarouselNext />
      </div>
    </Carousel>
  )
}

```

## API reference [#api-reference]

`Carousel` accepts native `div` props plus:

| Prop            | Values                       | Default      |
| --------------- | ---------------------------- | ------------ |
| `aria-label`    | string (required)            | —            |
| `orientation`   | `horizontal`, `vertical`     | `horizontal` |
| `loop`          | boolean                      | `false`      |
| `setApi`        | `(api: CarouselApi) => void` | —            |
| `onIndexChange` | `(index: number) => void`    | —            |

`CarouselApi` contains `index`, `count`, `canScrollPrev`, `canScrollNext`, `scrollTo(index)`, `scrollPrev()`, and `scrollNext()`. The same values are available to custom controls through the `useCarousel()` hook.

`CarouselContent`, `CarouselItem`, and `CarouselDots` accept native `div` props. `CarouselPrevious` and `CarouselNext` accept [Button](/docs/components/button) props and default to `variant="outline"` and `size="icon-sm"`.
