---
title: Rolling Text 3d
description: A premium 3D text rotation component that creates a 'Tube' rotation effect using GSAP. Each character rotates in a 3D cylindrical space for a high-impact cinematic feel.
---
## Installation
CLI
Manual
```bash
npx lightswind@latest add rolling-text-3d
```
Copy and paste the following code into your project.
```tsx
"use client";
import React, { useEffect, useRef } from "react";
import { gsap } from "gsap";
import { cn } from "@/components/lib/utils";
interface RollingText3DProps {
/**
* The text to be animated.
*/
text: string;
/**
* Font size of the text (e.g., "5vw", "48px").
* Defaults to "8vw" for a professional hero look.
*/
fontSize?: string;
/**
* Color of the text.
*/
color?: string;
/**
* Additional tailwind classes for the container.
*/
className?: string;
/**
* Duration of one full rotation cycle in seconds.
*/
duration?: number;
/**
* Stagger delay between characters.
*/
stagger?: number;
/**
* Perspective depth for the 3D effect.
*/
perspective?: number;
/**
* Letter spacing.
*/
letterSpacing?: string;
/**
* Number of duplicate lines in the "tube" (default is 4).
*/
linesCount?: number;
}
/**
* RollingText3D - A premium 3D text rotation component.
* Replicates the "Tube" rotation effect using GSAP.
*/
export const RollingText3D = ({
text,
fontSize = "8vw",
color = "currentColor",
className,
duration = 0.9,
stagger = 0.08,
perspective = 700,
letterSpacing = "-0.05em",
linesCount = 4,
}: RollingText3DProps) => {
const containerRef = useRef(null);
const tubeRef = useRef(null);
useEffect(() => {
if (!containerRef.current || !tubeRef.current) return;
const container = containerRef.current;
const lines = tubeRef.current.querySelectorAll(".rolling-line");
// Set initial visibility
gsap.set(container, { visibility: "visible" });
// Manually split text into characters for each line
// This allows us to avoid the paid GSAP SplitText plugin while keeping the effect.
lines.forEach((line) => {
const content = line.textContent || "";
line.innerHTML = "";
content.split("").forEach((char) => {
const span = document.createElement("span");
span.textContent = char === " " ? "\u00A0" : char;
span.style.display = "inline-block";
span.style.backfaceVisibility = "hidden";
line.appendChild(span);
});
});
const allLinesChars = Array.from(lines).map((line) =>
Array.from(line.querySelectorAll("span"))
);
// 3D setup logic
const update3D = () => {
const width = window.innerWidth;
const depth = -width / 8;
const transformOrigin = `50% 50% ${depth}px`;
gsap.set(lines, { perspective, transformStyle: "preserve-3d" });
const tl = gsap.timeline({ repeat: -1 });
allLinesChars.forEach((chars, index) => {
tl.fromTo(
chars,
{ rotationX: -90, opacity: 0 },
{
rotationX: 90,
opacity: 1,
stagger,
duration,
ease: "none",
transformOrigin
},
index * (duration / 2) // staggered entry for each line
);
});
return tl;
};
const timeline = update3D();
// Handle resize
const handleResize = () => {
timeline.kill();
update3D();
};
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
timeline.kill();
};
}, [text, duration, stagger, perspective, linesCount]);
return (
{Array.from({ length: linesCount }).map((_, i) => (
{text}
))}
);
};
```
## Usage
```tsx
import { RollingText3D } from "@/components/lightswind/rolling-text-3d"
```
```tsx
import { RollingText3D } from "@/components/lightswind/rolling-text-3d";
export function RollingTextDemo() {
return (
);
}
```