Text Flip
Cycles through words with a blur-and-rise transition.
textanimation
I build web apps
components/sidd-ui/text-flip.tsx
"use client"
import { cn } from "cn"
import { useEffect, useState } from "react"
export function TextFlip({
words,
interval = 3000,
className,
}: {
words: string[]
interval?: number
className?: string
}) {
const [index, setIndex] = useState(0)
useEffect(() => {
if (words.length < 2) return
const id = setInterval(() => setIndex((i) => (i + 1) % words.length), interval)
return () => clearInterval(id)
}, [words.length, interval])
return (
<span className={cn("relative inline-block", className)} aria-live="polite">
<span key={index} className="inline-block animate-[flip-in_450ms_ease-out]">
{words[index]}
</span>
</span>
)
}
Features
- Blur, fade and rise in one short keyframe.
- Configurable interval.
- Announces changes politely to screen readers.
Why I built this
One line is never enough to say what I do. Rotating a few short phrases under my name keeps the header clean and still tells the whole story.
Usage
example.tsx
<TextFlip words={["web apps", "CLIs", "APIs"]} />