Skip to content

Carousel

Slides in a row that snap into place. A swipe, the arrow buttons, the arrow keys and the dots all move the same scroll position, so they never disagree.

On this page
Used for
  • Prompt suggestions
  • Model cards
  • Template gallery
  • Onboarding steps
  • Result screenshots

Examples

One at a time

Installation

npx knowns-ui@latest add carousel
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

childrenrequired
ReactNode
One child per slide.
labelrequired
string
Names the carousel for screen readers.
perView
number, 1 to 4
Default1
Slides visible at once. A fraction such as 1.2 lets the next slide peek in.
perViewWide
number
DefaultperView
Slides visible from 640px up, e.g. 3 on a desktop and 1.2 on a phone.
gap
number
Default16
Space between slides, px.
arrows / dots
boolean
Defaulttrue
Show the arrow buttons and the dots.
onIndexChange
(index: number) => void
Called with the first slide in view, after a swipe or a button.
Keyboard
-
Focus the row: Left and Right move one slide, Home and End go to the ends.
Motion
browser smooth scroll
Only the scroll position moves. Reduced motion jumps.

What it handles

  1. 01Snaps each slide into place with native scroll-snap, so swipe, trackpad and wheel work with no script.
  2. 02Moves by arrow buttons, the arrow keys, Home and End and the dots, and disables an arrow at its end.
  3. 03Shows one to four slides at once with a set gap, and sizes them to fill the row exactly.
  4. 04Tells screen readers it is a carousel, names each slide as n of N, and marks the current dot.
  5. 05Follows the scroll for its index, so a swipe and a button always agree, and reports it through onIndexChange.
  6. 06Jumps instead of gliding when reduced motion is on.

States

First render
Nothing. The first slide is in place
none
Arrow or dot
The row glides to the slide
browser smooth scroll
Dot change
The current dot changes colour
120ms, ease out
Arrow hover
Background changes
120ms, ease out
Reduced motion
The row jumps to the slide
0ms

Works with

When to use

When to use

  • A short row of equal cards that does not fit: prompt suggestions, model cards, a template gallery.

When not to use

  • Content people must all see: lay it out in a grid: use Card.
  • Steps of a flow in order: use Stepper.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Carousel to my app and wire it to my own data.
  • I need a short row of equal cards that does not fit: prompt suggestions, model cards, a template gallery. Set that up with the Knowns UI Carousel.
  • Which Carousel props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "carousel" }) and search_docs({ query: "carousel" }).

Need help?

Stuck on Carousel, or found something off? We read every message.