This component requires the
motion-sv dependency.Installation
Usage
Examples
Basic Example
Simple word rotation with default settings.Custom Duration
Control how long each word is displayed.Different Element Types
Render as different HTML elements.Custom Motion Props
Define custom animation behavior.In a Sentence
Combine with other text for dynamic headlines.Feature Highlights
Rotate through product features.Multiple Rotations
Use multiple word rotates in a single sentence.Props
Array of words to rotate through. The component will cycle through these words infinitely.
Duration in milliseconds that each word is displayed before transitioning to the next.
Custom motion properties for the animation. Default:
The HTML element type to render. Options:
div, span, p, h1, h2, h3, h4, h5, h6.Additional CSS classes to apply to the component.
Animation Modes
The component uses AnimatePresence withmode="wait" which means:
- Current word exits completely before next word enters
- Only one word is rendered at a time
- Smooth, clean transitions without overlap
Default Animation
The default motion properties create:- Words slide in from above (y: -50)
- Fade in as they enter
- Slide out downward (y: 50)
- Fade out as they exit
- Quick 0.25s transitions
How It Works
- Interval-based cycling: Uses
setIntervalto change words at the specified duration - Reactive index: Index updates trigger Svelte’s reactivity
- AnimatePresence: Handles enter/exit animations smoothly
- Key-based rendering: Uses
{#key}block to trigger animations on word change - Cleanup: Interval is properly cleared on component unmount
Customization
Slide From Right
Scale Animation
Rotate Animation
Blur Transition
No Animation (Just Fade)
Spring Physics
Use Cases
- Hero headlines: Create dynamic, attention-grabbing titles
- Feature showcases: Rotate through product benefits
- Job titles: “I’m a Developer | Designer | Creator”
- Brand values: Cycle through company values or mission statements
- Multi-purpose products: Show different use cases
- Testimonial highlights: Rotate key quotes or feedback
- Status indicators: Show different states or modes
Best Practices
- Similar length: Words of similar length look better when rotating
- Meaningful order: Consider the order of words for flow
- Appropriate duration: 2-3 seconds per word is usually optimal
- Context: Ensure rotating words make sense in the sentence context
- Limit words: 3-6 words work best; too many can be overwhelming
- Color contrast: Use contrasting colors to make rotating words stand out
Performance
The component is optimized:- Uses motion-sv for GPU-accelerated animations
- Properly cleans up intervals on unmount
- Only one word is rendered at a time (wait mode)
- Efficient Svelte reactivity for updates
Accessibility
Considerations:- Rapidly changing text may be difficult for some users to read
- Ensure critical information isn’t only in rotating text
- Consider adding a pause button for accessibility
- The text changes may not be announced to screen readers
The component includes a note in the source code mentioning that the animation behavior differs slightly from the React implementation due to Svelte/motion-sv specifics.