Use our Tailwind CSS carousel using swiper for your website for sliding through multiple elements or images.
See below our beautiful carousel examples that you can use in your Tailwind CSS and React project. The examples below are using swiper library, make sure to install it before using the example.
We're using swiper
library for making carousel components. Make sure to install it before using the example.
npm install swiper
npm install swiper
"use client";
import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
import * as React from "react";
import { Navigation, Pagination } from "swiper/modules";
import { IconButton } from "@material-tailwind/react";
import { NavArrowRight, NavArrowLeft } from "iconoir-react";
import { Swiper, SwiperSlide, useSwiper } from "swiper/react";
function CustomNavigation() {
const swiper = useSwiper();
return (
<>
<IconButton
isCircular
size="lg"
variant="ghost"
color="secondary"
onClick={() => swiper.slidePrev()}
className="dark !absolute left-2 top-1/2 z-10 -translate-y-1/2"
>
<NavArrowLeft className="h-7 w-7 -translate-x-0.5 stroke-2" />
</IconButton>
<IconButton
isCircular
size="lg"
variant="ghost"
color="secondary"
onClick={() => swiper.slideNext()}
className="dark !absolute right-2 top-1/2 z-10 -translate-y-1/2"
>
<NavArrowRight className="h-7 w-7 translate-x-px stroke-2" />
</IconButton>
</>
);
}
function customPagination(_, className) {
return `<span class="${className} w-4 h-4 [&.swiper-pagination-bullet-active]:!opacity-100 [&.swiper-pagination-bullet-active]:[background:rgb(var(--color-background))] !opacity-50 ![background:rgb(var(--color-background))]"></span>`;
}
export function CarouselDemo() {
return (
<div className="max-w-[686px]">
<Swiper
pagination={{
enabled: true,
clickable: true,
dynamicBullets: true,
renderBullet: customPagination,
}}
modules={[Navigation, Pagination]}
className="relative rounded-lg [&_div.swiper-button-next]:text-background [&_div.swiper-button-prev]:text-background"
>
{[
"https://images.unsplash.com/photo-1470813740244-df37b8c1edcb?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NHx8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://plus.unsplash.com/premium_photo-1673603988651-99f79e4ae7d3?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://images.unsplash.com/photo-1465189684280-6a8fa9b19a7a?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTZ8fG5hdHVyZXxlbnwwfDB8MHx8fDA%3D",
"https://images.unsplash.com/photo-1458668383970-8ddd3927deed?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8N3x8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fG5hdHVyZXxlbnwwfDB8MHx8fDA%3D",
].map((img, index) => (
<SwiperSlide key={index} className="select-none">
<img
src={img}
alt={`image-${index}`}
className="h-[28rem] w-full object-cover"
/>
</SwiperSlide>
))}
<CustomNavigation />
</Swiper>
</div>
);
}
"use client";
import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
import * as React from "react";
import { Navigation, Pagination } from "swiper/modules";
import { IconButton } from "@material-tailwind/react";
import { NavArrowRight, NavArrowLeft } from "iconoir-react";
import { Swiper, SwiperSlide, useSwiper } from "swiper/react";
function CustomNavigation() {
const swiper = useSwiper();
return (
<>
<IconButton
isCircular
size="lg"
variant="ghost"
color="secondary"
onClick={() => swiper.slidePrev()}
className="dark !absolute left-2 top-1/2 z-10 -translate-y-1/2"
>
<NavArrowLeft className="h-7 w-7 -translate-x-0.5 stroke-2" />
</IconButton>
<IconButton
isCircular
size="lg"
variant="ghost"
color="secondary"
onClick={() => swiper.slideNext()}
className="dark !absolute right-2 top-1/2 z-10 -translate-y-1/2"
>
<NavArrowRight className="h-7 w-7 translate-x-px stroke-2" />
</IconButton>
</>
);
}
function customPagination(_, className) {
return `<span class="${className} w-4 h-4 [&.swiper-pagination-bullet-active]:!opacity-100 [&.swiper-pagination-bullet-active]:[background:rgb(var(--color-background))] !opacity-50 ![background:rgb(var(--color-background))]"></span>`;
}
export function CarouselDemo() {
return (
<div className="max-w-[686px]">
<Swiper
pagination={{
enabled: true,
clickable: true,
dynamicBullets: true,
renderBullet: customPagination,
}}
modules={[Navigation, Pagination]}
className="relative rounded-lg [&_div.swiper-button-next]:text-background [&_div.swiper-button-prev]:text-background"
>
{[
"https://images.unsplash.com/photo-1470813740244-df37b8c1edcb?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NHx8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://plus.unsplash.com/premium_photo-1673603988651-99f79e4ae7d3?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://images.unsplash.com/photo-1465189684280-6a8fa9b19a7a?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTZ8fG5hdHVyZXxlbnwwfDB8MHx8fDA%3D",
"https://images.unsplash.com/photo-1458668383970-8ddd3927deed?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8N3x8bmF0dXJlfGVufDB8MHwwfHx8MA%3D%3D",
"https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=1600&auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fG5hdHVyZXxlbnwwfDB8MHx8fDA%3D",
].map((img, index) => (
<SwiperSlide key={index} className="select-none">
<img
src={img}
alt={`image-${index}`}
className="h-[28rem] w-full object-cover"
/>
</SwiperSlide>
))}
<CustomNavigation />
</Swiper>
</div>
);
}