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 carouselFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Carousel from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/carousel
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add carousel
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/carousel/carousel.tsx
- components/ui/knowns/carousel/carousel-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/carousel, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "carousel" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- childrenrequired
ReactNode- One child per slide.
- labelrequired
string- Names the carousel for screen readers.
- perView
number, 1 to 4- Default
1 - Slides visible at once. A fraction such as 1.2 lets the next slide peek in.
- perViewWide
number- Default
perView - Slides visible from 640px up, e.g. 3 on a desktop and 1.2 on a phone.
- gap
number- Default
16 - Space between slides, px.
- arrows / dots
boolean- Default
true - 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| childrenrequired | ReactNode | required | One child per slide. |
| labelrequired | string | required | Names the carousel for screen readers. |
| perView | number, 1 to 4 | 1 | Slides visible at once. A fraction such as 1.2 lets the next slide peek in. |
| perViewWide | number | perView | Slides visible from 640px up, e.g. 3 on a desktop and 1.2 on a phone. |
| gap | number | 16 | Space between slides, px. |
| arrows / dots | boolean | true | 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
- 01Snaps each slide into place with native scroll-snap, so swipe, trackpad and wheel work with no script.
- 02Moves by arrow buttons, the arrow keys, Home and End and the dots, and disables an arrow at its end.
- 03Shows one to four slides at once with a set gap, and sizes them to fill the row exactly.
- 04Tells screen readers it is a carousel, names each slide as n of N, and marks the current dot.
- 05Follows the scroll for its index, so a swipe and a button always agree, and reports it through onIndexChange.
- 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
| State | What moves | Timing |
|---|---|---|
| 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
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" }).