---
title: 3d Image Slider
description: A professional responsive 3D image slider component using Framer Motion and Tailwind CSS. Features smooth rotation, customizable perspective, and CSS 3D transforms.
---
## Installation
CLI
Manual
```bash
npx lightswind@latest add 3d-image-slider
```
Copy and paste the following code into your project.
```tsx
"use client";
import React, { useRef } from "react";
import { motion, useReducedMotion, useInView } from "framer-motion";
const DEFAULT_DATA = [
"https://images.unsplash.com/photo-1540968221243-29f5d70540bf?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1596135187959-562c650d98bc?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1628944682084-831f35256163?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1590013330451-3946e83e0392?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1590421959604-741d0eec0a2e?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1572613000712-eadc57acbecd?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1570097192570-4b49a6736f9f?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1620789550663-2b10e0080354?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1617775623669-20bff4ffaa5c?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1548600916-dc8492f8e845?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1573824969595-a76d4365a2e6?w=800&auto=format&fit=crop&q=60",
"https://images.unsplash.com/photo-1633936929709-59991b5fdd72?w=800&auto=format&fit=crop&q=60",
];
interface Slider3DProps {
/** Array of image URLs to display */
images?: string[];
/** Duration of one full 360-degree rotation (in seconds) */
duration?: number;
/** Width of each card. Can be px, rem, em, etc. */
cardWidth?: string;
/** CSS aspect ratio of the cards */
cardAspectRatio?: string;
/** CSS perspective value for the 3D container */
perspective?: string;
/** Additional classes for the outermost container */
containerClassName?: string;
/** Additional classes for the individual image elements */
imageClassName?: string;
/** Direction of the rotation */
rotationDirection?: "left" | "right";
/** Whether to apply a gradient fade mask on the edges */
withMask?: boolean;
}
export default function ImageSlider3D({
images = DEFAULT_DATA,
duration = 32,
cardWidth = "17.5em",
cardAspectRatio = "7/10",
perspective = "35em",
containerClassName = "",
imageClassName = "",
rotationDirection = "left",
withMask = true,
}: Slider3DProps) {
const n = images.length;
const containerRef = useRef(null);
const isInView = useInView(containerRef, { margin: "200px" });
const prefersReducedMotion = useReducedMotion();
const animationDuration = prefersReducedMotion ? duration * 4 : duration;
// rotation angles based on direction
const rotationValues = rotationDirection === "left" ? [0, 360] : [360, 0];
const maskStyles = withMask
? {
WebkitMask:
"linear-gradient(90deg, transparent, #000 20% 80%, transparent)",
mask: "linear-gradient(90deg, transparent, #000 20% 80%, transparent)",
}
: {};
return (
{images.map((src, i) => (
))}
);
}
```
## Usage
```tsx
import ImageSlider3D from "@/components/lightswind/3d-image-slider"
```
```tsx
import ImageSlider3D from "@/components/lightswind/3d-image-slider";
export function ThreeDImageSliderDemo() {
return (
);
}
```