my/ui

Command Palette

Search for a command to run...

All components

Word Rotate

text

A vertical rotation of words

responsive · 360px

Install

Same command in any shadcn project — React (Vite/CRA), Next.js, Remix, Astro, and more:

$npx shadcn@latest add https://your-domain/r/word-rotate.json

Usage

"use client";
import { WordRotate } from "@/registry/magic-ui/word-rotate";

export default function Demo() {
  return (
    <div className="flex items-center justify-center w-full max-w-md p-8">
      <WordRotate
        className="text-4xl font-bold text-black dark:text-white"
        words={["Innovative", "Scalable", "Reliable", "Fast", "Beautiful"]}
      />
    </div>
  );
}

Component source

"use client"

import { useEffect, useState } from "react"
import { AnimatePresence, motion, type MotionProps } from "motion/react"

import { cn } from "@/lib/utils"

interface WordRotateProps {
  words: string[]
  duration?: number
  motionProps?: MotionProps
  className?: string
}

export function WordRotate({
  words,
  duration = 2500,
  motionProps = {
    initial: { opacity: 0, y: -50 },
    animate: { opacity: 1, y: 0 },
    exit: { opacity: 0, y: 50 },
    transition: { duration: 0.25, ease: "easeOut" },
  },
  className,
}: WordRotateProps) {
  const [index, setIndex] = useState(0)

  useEffect(() => {
    const interval = setInterval(() => {
      setIndex((prevIndex) => (prevIndex + 1) % words.length)
    }, duration)

    // Clean up interval on unmount
    return () => clearInterval(interval)
  }, [words, duration])

  return (
    <div className="overflow-hidden py-2">
      <AnimatePresence mode="wait">
        <motion.h1
          key={words[index]}
          className={cn(className)}
          {...motionProps}
        >
          {words[index]}
        </motion.h1>
      </AnimatePresence>
    </div>
  )
}

Dependencies

motion

Source: Magic UI