A composable, scroll-snap powered carousel for React and TailwindCSS. Build your own navigation, transitions, and carousel behavior with ease.
- 🧱 Agnostic: Render anything — images, cards, or custom components.
- 🧩 Composable: Build your own UI — arrows, dots, autoplay, or custom transitions.
- ⚙️ Hooks-first: Powered by
useCarouseland React context — no massive config objects. - 💨 Smooth: Uses native scroll behavior with
scroll-snap. - 🧠 Typed: Full TypeScript support.
- 🪶 Lightweight: No external dependencies beyond React and Tailwind.
- Install the package with your preferred package manager:
pnpm add @k3vndev/react-carousel- Enable Tailwind to read the package utilities and classes:
@import"tailwindcss";
@source"../node_modules/@k3vndev/react-carousel";import{Carousel,CarouselItem,NavigationArrows}from'@k3vndev/react-carousel'<CarouselitemsCount={catImages.length}className="w-110"navigationHandler={<NavigationArrows/>}>{catImages.map(src=>(<CarouselItemclassName="h-150 rounded-xl"key={src}><imgsrc={src}className="object-cover size-full"alt="A cat, probably angry"/></CarouselItem>))}</Carousel>| Component | Description |
|---|---|
Carousel | Main carousel container |
CarouselItem | Individual slide |
NavigationArrows | Arrow navigation handler |
NavigationDots | Dot navigation handler |
Components passed to the navigationHandler prop control the carousel navigation.
You can use multiple handlers at the same time.
| Component | Description |
|---|---|
NavigationArrows | Two arrow buttons for horizontal navigation |
NavigationDots | A row of circular buttons to navigate between slides |
You can create your own navigation handlers using the useCarousel hook.
const{ carouselNavigator, carouselData }=useCarousel()This hook returns two objects:
carouselNavigator— functions to control carousel navigationcarouselData— useful data about the carousel's current state
| Function | Description |
|---|---|
scrollLeft(itemsDistance?: number) | Scrolls left by n slides. Defaults to 1. |
scrollRight(itemsDistance?: number) | Scrolls right by n slides. Defaults to 1. |
scrollToIndex(index: number) | Scrolls directly to a specific slide |
useCarousel relies on React context, so it must be used within a Carousel component — typically inside a navigationHandler.
You can apply your own Tailwind classes, CSS, or inline styles.
Example:
<NavigationDotsclassName="[&>.dot.active]:bg-yellow-400"/>Contributions are welcome! If you have ideas for improvements, new features, or bug fixes, feel free to open an issue or submit a pull request.
