Search documentation v0.9.0

Rotating Text

Animate through a series of words

Source ↗️ Report Issue ↗️

Use the RotatingText component to display dynamic text that changes through a series of words using animations. They are space efficient and can improve engagement. Use it to highlight key features, services, or taglines, or to display changing headlines or testimonials.

Preview
AstroSvelteReact
Unlock code
How to use the RotatingText component in Astro
<RotatingText
words={['Astro', 'Svelte', 'React']}
colors={['#B545ED', '#FF3E00', '#61DAFB']}
/>

The RotatingText component only requires a words prop that defines a list of words to loop through in the form of an array of strings. You can customize text colors by defining the colors prop. The colors are matched to the index of the words array.

Delay

To customize the animation, you can configure the letter and word delay using the letterDelayAmount and wordDelayAmount props:

letterDelayAmountSet to 100 ms
wordDelayAmountSet to 2000 ms
Unlock code
How to delay letter animation
<RotatingText
words={['letterDelayAmount', 'Set to 100 ms']}
letterDelayAmount={100}
/>
Unlock code
How to delay word rotation
<RotatingText
words={['wordDelayAmount', 'Set to 2000 ms']}
wordDelayAmount={2000}
/>

Animation Speed

Similar to configuring letter and word timing, you can also configure the animation timing using the animationInterval prop. The lower the value, the faster the animation becomes:

animationIntervalSet to 1000 ms
Unlock code
animationInterval is set to 4000ms by default
<RotatingText
words={['animationInterval', 'Set to 1000 ms']}
animationInterval={1000}
/>

Customize Animation

The animation can be further customized using the transformOrigin prop. This changes the transform origin property of the letters that are animated using transforms:

DefaulttransformOrigin
bottom left 10pxtransformOrigin
centertransformOrigin
Unlock code
How to customize animation
<RotatingText
words={['bottom left 10px', 'transformOrigin']}
transformOrigin="bottom left 10px"
/>
Unlock code
How to customize animation
<RotatingText
words={['center', 'transformOrigin']}
transformOrigin="center"
/>

Customize with CSS

The animation can also be customize via CSS. If you want to globally set the transformOrigin prop, remove the prop from your components and override the following CSS variable instead:

Unlock code
How to customize animation through CSS
html body {
--w-rotating-text-transform-origin: center center 20px; // Default value
}

API

Unlock code
Component API reference
type RotatingTextProps = {
words: string[]
colors?: string[]
letterDelayAmount?: number
wordDelayAmount?: number
animationInterval?: number
transformOrigin?: string
className?: string
}
PropDefaultPurpose
words [] Sets the words that are animated.
colors [] Sets the color of each word. Matches the index of the words prop.
letterDelayAmount 30 ms Sets the animation delay between each letter.
wordDelayAmount 300 ms Sets the animation delay between each word.
animationInterval 4000 ms Sets the speed of the animation.
transformOrigin center Sets the transform origin for the letters.
className - Pass additional CSS classes for the text.