GooseUI

Components

Carousel

New

A server-rendered carousel on native CSS scroll-snap. Slides swipe and snap by themselves, the dots and image thumbnails are links to the slides, and the focused track scrolls with the arrow keys, all without JavaScript. A client script of about 1 kB enables the arrow buttons, marks the active dot, updates the counter and progress bar and runs auto-play.

Browser Support

Scroll snap

Aligns items while scrolling

Your browser:
scroll-target-group

Tracks the current scroll target

Your browser:
::scroll-button

Creates scroll controls

Your browser:
scripting media query

Adapts controls to JavaScript availability

Your browser:
color-mix()

Colors the CSS scroll buttons

Your browser:
scrollbar-width

Hides the scrollbar

Your browser:
overscroll-behavior

Contains scroll gestures

Your browser:

Preview

Swipe, click the dots, or focus the slides and use the arrow keys.

Installation

npx shadcn@latest add @gooseui/carousel
pnpm dlx shadcn@latest add @gooseui/carousel
yarn dlx shadcn@latest add @gooseui/carousel
bunx --bun shadcn@latest add @gooseui/carousel

Usage

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

export default function Example() {
  return (
    <Carousel>
      <CarouselItem>Slide 1</CarouselItem>
      <CarouselItem>Slide 2</CarouselItem>
      <CarouselItem>Slide 3</CarouselItem>
      <CarouselPrevious />
      <CarouselNext />
      <CarouselDots />
    </Carousel>
  )
}

Examples

With Progress Bar

<Carousel>
  {items.map((item) => (
    <CarouselItem key={item.id}>{item.content}</CarouselItem>
  ))}
  <CarouselPrevious />
  <CarouselNext />
  <div className="mt-4 space-y-2">
    <CarouselProgress />
    <CarouselCounter />
  </div>
</Carousel>

Number Indicators

<CarouselDots variant="numbers" />

Line Indicators

<CarouselDots variant="line" />

Multiple Items

<CarouselItem size="1/3">
  {/* Shows 3 items at once */}
</CarouselItem>

Auto-Play with Loop

Auto-play pauses on hover and on keyboard focus and does not start when the user prefers reduced motion.

<Carousel autoPlay={3000} loop>
  {/* Auto-advances every 3 seconds */}
</Carousel>

Vertical

<Carousel orientation="vertical" className="h-[400px]">
  {/* Vertical scrolling */}
</Carousel>

Thumbnails

CarouselThumbnails adds a strip of image links under, left or right of the slides, the way product galleries do. Each thumbnail is a link to its slide, so it works without JavaScript. The client script marks the active thumbnail and keeps it in view as the strip scrolls. With a single slide the strip is not rendered.

Product gallery

const images = [
  { src: "/photos/1.webp", thumbnail: "/photos/1-thumb.webp", alt: "Front view" },
  { src: "/photos/2.webp", thumbnail: "/photos/2-thumb.webp", alt: "Side view" },
  { src: "/photos/3.webp", thumbnail: "/photos/3-thumb.webp", alt: "Back view" },
]

<Carousel>
  {images.map((image) => (
    <CarouselItem key={image.src}>
      <img src={image.src} alt={image.alt} className="aspect-[4/3] w-full rounded-xl object-cover" />
    </CarouselItem>
  ))}
  <CarouselPrevious />
  <CarouselNext />
  <CarouselThumbnails images={images} />
</Carousel>

Vertical strip on the left

The strip takes the height of the slides and scrolls on its own when there are more thumbnails than fit.

<Carousel>
  {/* slides */}
  <CarouselThumbnails images={images} position="left" />
</Carousel>

Props

Carousel

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Scroll direction
loopbooleanfalseArrows jump from the last slide to the first and back
autoPlaynumber0Auto-play interval in ms, 0 turns it off
pauseOnHoverbooleantruePause auto-play while the pointer is over the carousel
draggableboolean-Kept for compatibility, has no effect

CarouselItem

PropTypeDefaultDescription
size"full" | "1/2" | "1/3" | "1/4" | "auto""full"Item width

CarouselPrevious / CarouselNext

PropTypeDefaultDescription
iconSizenumber16Size of the default chevron icon
childrenReactNode-Custom button content instead of the chevron

CarouselThumbnails

PropTypeDefaultDescription
images{ src: string; alt?: string; thumbnail?: string }[]-One entry per slide: src, alt and an optional smaller thumbnail image
position"bottom" | "left" | "right""bottom"Where the strip sits, left and right make it vertical
slideLabel(index: number) => stringGo to slide NAccessible name of each dot or thumbnail link

CarouselDots

PropTypeDefaultDescription
variant"dots" | "line" | "numbers""dots"Indicator style
slideLabel(index: number) => stringGo to slide NAccessible name of each dot or thumbnail link

Features

  • Server component: markup and dots are rendered on the server, only the controller is client code
  • CSS Scroll Snap: native swipe and snapping, no scroll math in JS
  • Dot links: every dot is an anchor to its slide and works without JS
  • Keyboard: the track is focusable, arrow keys scroll it
  • Indicators: dots, lines, numbers, progress bar and counter
  • Thumbnails: image strip below or beside the slides, replaces a separate gallery component
  • Reduced motion: smooth scrolling and auto-play are off when the user asks for less motion

Migration

  • useCarousel is removed: Carousel is a server component now and has no React context
  • Dots are links with aria-current instead of tab buttons
  • Dots, progress and counter must sit inside Carousel or inside plain elements in it
  • draggable no longer does anything (it was a no-op before as well)
  • Thumbnail Gallery is merged into Carousel: use CarouselThumbnails with images and position instead of ThumbnailGallery