Words that take turns in place, each one sliding out as the next slides in.
Installation
Usage
import {
RotatingText,
RotatingTextContainer,
} from '@animate-ui/react/primitives/texts/rotating';
export function Tagline() {
return (
<RotatingTextContainer text={['Fast', 'Accessible', 'Animated']}>
<RotatingText />
</RotatingTextContainer>
);
}Animation
- After
delay(right away by default), the current word slides out byywhile fading, then the next one slides in from the other side: 0.3s each on an ease-out, one after the other. The next swaps follow everyduration. With no delay, the first word leaves as soon as it mounts, so the second one is the first to show. - The cycle pauses off screen and in a hidden tab.
<AnimateUIProvider tempo>paces the default transition.- Under reduced motion, the words keep taking turns as a crossfade, without travel.
- With
align, the container keeps the width of its longest text, so a word swap never moves the text around it, and each word sits at the start, center or end of that width. - Screen readers read every word once, never the cycling one.
API Reference
RotatingTextContainer
| Prop | Type | Default |
|---|---|---|
text | string | string[] | - |
duration? | number | 2000 |
y? | number | -50 |
delay? | number | 0 |
align? | 'start' | 'center' | 'end' | - |
inView? | boolean | false |
inViewMargin? | string | '0px' |
inViewOnce? | boolean | true |
...props? | React.ComponentProps<'div'> | - |
RotatingText
| Prop | Type | Default |
|---|---|---|
transition? | Transition | { duration: 0.3, ease: 'easeOut' } |
...props? | Omit<HTMLMotionProps<'div'>, 'children'> | - |
useRotatingText
Returns the container's state inside it: { currentText, y, isInView, label }.