<SplitText> component wraps a single child element and splits its text content into characters, words, and/or lines. It handles lifecycle cleanup automatically on unmount and provides callbacks for animation control.
Import
Basic Usage
How It Works
The<SplitText> component:
- Wraps your element - Wraps a single child element (like
<h1>,<p>, etc.) in a container - Waits for fonts - By default, waits for
document.fonts.readybefore splitting - Splits the text - Breaks text into spans based on your split type (chars, words, lines)
- Applies kerning compensation - Adjusts margins to preserve original spacing
- Calls your callback - Provides split elements to
onSplit,onViewportEnter, oronViewportLeave
Key Concepts
Wrapper Element
The component creates a wrapper element (default:<div>) around your child. You can customize this:
Single Child Requirement
The component accepts only one child element. To split multiple elements, use multiple<SplitText> components:
Callback Modes
The component supports three callback modes:- onSplit - Called immediately after splitting (default behavior)
- onViewportEnter/onViewportLeave - Called when element enters/leaves viewport
- Both - Use
onSplitfor initial setup and viewport callbacks for scroll animations
Related Pages
- Props - Complete props reference with examples
- Lifecycle - Component lifecycle and event timing
- Return Value - SplitTextElements return type for callbacks