splitText()

Use splitText() to split DOM text into chars, words, and lines.

Parameters

element

HTMLElement — The DOM element containing text to split.

options

Return Value

Font Loading

For stable kerning measurements, wait until fonts are loaded before splitting:

The React and Motion components do this by default. Pass waitForFonts={false} to skip waiting.

Accessibility

Griffo keeps split text readable by screen readers. The accessibility strategy depends on element type.

Headings and Landmarks

For elements that support aria-label (headings, <section>, <nav>, etc.), Griffo adds aria-hidden="true" to split spans and sets aria-label on the parent:

If the element already has an aria-label, Griffo preserves it.

Generic Elements and Nested Content

For elements like <span>, <div>, and <p> (which do not support aria-label), or when content includes inline elements like links/emphasis, Griffo hides the visual split output and adds a screen-reader-only copy:

The same approach works for nested inline content while preserving semantics for assistive technology:

Authored hard breaks are preserved. Explicit <br> and block-level descendants become hard boundaries; in chars/words modes those boundaries are normalized to <br> in split output.

Examples

Basic Split

Split text and animate with any animation library.

With Auto-Revert

Use onSplit for the animation and revertOnComplete to restore original HTML when it finishes.

Responsive Split

Enable autoSplit to re-split text on container resize. onResplit runs whenever a full resplit replaces split output.

If you use scroll-linked/scroll-triggered animation with autoSplit + lines, reattach that setup in onResplit so it binds to the new elements.

Call revert() when you no longer need the split.

Masked Reveal

Use mask to wrap elements in a clipping container for reveal animations where content moves in from outside bounds.

Nested HTML Elements

Griffo preserves inline elements like <a>, <em>, and <strong>, including attributes (href, class, data-*, etc.).

With Initial Styles

Use initialStyles to set start states without looping. Styles are applied after split and kerning compensation.

You can also use a function for per-element customization:

With CSS Variables

Enable propIndex to add --char-index, --word-index, and --line-index CSS variables to each element.

For practical usage patterns, see the Vanilla examples.