Overview
ThesplitText function splits text into individual characters, words, and/or lines while preserving the original kerning (letter spacing). This prevents the visual “jumping” that occurs with naive text splitting.
Griffo measures character positions before splitting, then applies margin adjustments after splitting to maintain visual fidelity.
Import
Function Signature
Parameters
The HTML element containing text to split. Must have text content.
Configuration options for splitting behavior. See the Options page for detailed documentation.
Returns
Returns aSplitTextResult object containing arrays of split elements and utility functions. See the Return Value page for detailed documentation.
Basic Usage
Split Types
Control which elements to create using thetype option:
Auto-Revert After Animation
Automatically revert the split after an animation completes:- Motion: Returns objects with
.finishedPromise - GSAP: Returns thenables with
.then()method - Raw Promises: Supported directly
Responsive Re-Splitting
Automatically re-split text when the container resizes:The
autoSplit option requires the element to have a parent element. It observes the parent’s width to detect when lines may have changed.Custom Classes
Apply custom class names to split elements:Mask Wrappers
Add overflow mask wrappers for reveal animations:overflow: clip, perfect for slide-in animations.
CSS Custom Properties
Add CSS custom properties with indices:--char-index, --word-index, and --line-index CSS custom properties to each element:
Errors
Throws if
element is not an HTMLElementWarnings
- If element has no text content, logs a warning and returns empty arrays
- If
autoSplitis enabled but element has no parent, logs a warning - If
typedoesn’t include at least one of chars/words/lines, logs a warning and defaults to all three
Accessibility
Griffo automatically handles accessibility:- For elements that support
aria-label(headings, landmarks, interactive elements), the original text is set asaria-label - For other elements (span, div, p), a screen-reader-only copy of the original HTML is injected
- Split elements are marked with
aria-hidden="true"to hide them from screen readers
See Also
- Options - Detailed options documentation
- Return Value - Return value documentation
- Kerning - How kerning compensation works