Split Text
A text reveal. The element splits its own text into words, characters or detected lines, wraps each unit in a masked span, and animates them in on a CSS-driven stagger. Eight built-in effects, and the animation itself is pure CSS keyed off a per-unit index.
This piece is a wrapper, not a port: it renders the real <split-text> custom element from @magic-spells/split-text and binds attributes to it. The parts worth not forking are the grapheme-correct character splitter, the lines mode that measures the real wrap after the fonts load, and the aria bookkeeping that keeps a screen reader from reading the sentence one span at a time.
Under prefers-reduced-motion: reduce nothing on this page animates: the element short-circuits before it splits anything and the text is simply there.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece split-text
This piece has a runtime dependency: the web component it wraps.
npm install @magic-spells/split-text
Then merge the component's stylesheet into your app's style entry (app/styles/styles.css). The masks, the resting transforms and every effect's keyframes live in it, so the piece renders plain unanimated text without it:
/* app/styles/styles.css */ @import "tailwindcss"; @import "@magic-spells/split-text/css" layer(components);
layer(components) is not decoration. The sheet is plain element selectors (split-text, .split-text-word), and an unlayered import would outrank the Tailwind type utilities you put on the element.
Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import SplitText from '@/components/ui/SplitText.pzl';
<SplitText class="text-4xl font-semibold text-ink"> Built for the web, not for the framework. </SplitText> // The content must be literal markup, not a changing interpolation — // the element rewrites its own text nodes into masked spans at connect.
Content is static
This is the one rule the piece asks you to keep. Children pass through untouched, and at connect the element replaces its own text nodes with nested spans. Puzzle's patcher no longer owns that subtree, so the content you pass must be literal markup, never an interpolation that changes underneath it. Inline tags are preserved by the splitter and are fine — links stay clickable, emphasis still styles, a line break still breaks a line.
To show different text, change the text and bump play in the same render: the element restores its own snapshot, adopts whatever markup is there now, and re-splits it.
The same applies to the attributes. The element declares no observed attributes — split, effect, the three timings, the easing and the trigger are read once, when it splits. Changing one of those props renders the new attribute but changes nothing on screen until the next split, so bump play to re-read them. That is exactly what the effect gallery below does.
Characters, with a slower stagger
Lines, detected from the real wrap
The eight effects
Scroll-triggered — the default
Everything above is set to fire on load so the page is not a field of frozen text. The real default is trigger="visible": nothing happens until the element has scrolled a fifth of the way up from the bottom of the viewport. Keep scrolling.
Move the trigger line with offset — offset="0" fires the instant the element first intersects, offset="200px" waits until it is 200 pixels clear of the bottom edge. It fires once; reload or bump play to see it again.
Reference
Every prop but play maps to an attribute on the element. A prop you don't pass renders no attribute at all, so the component's own default applies.
Props
split'words' (default) | 'chars' | 'lines'. Lines are detected from the layout after the fonts load, so they follow the real wrap.effect'rise' (default) | 'drop' | 'slide-right' | 'slide-left' | 'bloom' | 'spin-x' | 'spin-y' | 'magnetic', or any name registered with SplitText.registerEffect(). An unknown name falls back to the default keyframe.delayMilliseconds before the first unit animates. Default 0.staggerMilliseconds between units. Default 30 — lower it for chars on a long string, raise it for lines.durationMilliseconds per unit. Default 800.easingCSS easing function. Default cubic-bezier(0.16, 1, 0.3, 1). A spring overshoot like cubic-bezier(0.34, 1.56, 0.64, 1) reads playful.trigger'visible' (default, an IntersectionObserver) | 'load' (next microtask) | 'manual' (only the play token fires it).offsetHow far above the bottom of the viewport the visible trigger fires, in px or %. Default '20%'; '0' fires on first intersection.playThe replay token — any value the parent changes. A render whose play differs from the last one re-splits the element and re-arms its trigger; a render carrying the same value does nothing. Not an attribute, and never written back.classMerged onto the element. Type utilities go here, and so do the custom properties, as arbitrary-property utilities.Callbacks
Both are value-first: the piece hands you the element's own detail object, { split, count } — the mode that actually ran and the number of animating units (lines, not words, in lines mode).
@startThe reveal has begun. Fires once per split, never per unit.@completeThe last unit has landed. Also fires immediately, with count 0, when reduced motion or an empty host short-circuits the animation — so it reliably means "the text is now in its final state".Custom properties
There is no style prop: the element writes the resolved timings into the host's inline style at every split, and a bound style attribute would be rewritten wholesale by the patcher. Set these through class instead — they are inherited, so an arbitrary-property utility on the element or on any ancestor reaches them: class="[--split-text-distance:40%]".
--split-text-distanceTravel distance for rise / drop / slide-*. Default 100% of the unit; 40% is a subtler version of the same move.--split-text-blurStarting blur radius for bloom and magnetic. Default 2px.--split-text-scaleBloom's starting scale. Default 0.7.--split-text-perspectiveCamera distance for spin-x / spin-y, set on the host. Default 2000px — shorten it for a harder flip.--split-text-origintransform-origin for the spins. Defaults to bottom for spin-x and left for spin-y.--split-text-jitterPer-unit timing offset in stagger steps, written by a registered perUnit hook. 0 is a perfectly even stagger.Accessibility and first paint
- The sentence is announced once. The element copies its plain text into
aria-labeland marks the generated wrappersaria-hidden. Wrappers inside an interactive ancestor are left alone, so a nested link keeps its accessible name. Don't set an aria-label yourself — the element only fills in an absent one, and a stale one would win. - Reduced motion is handled upstream, and early. The element marks itself revealed in its connect path and returns before it splits anything: no spans, no keyframes, no observer.
@completestill fires with a count of 0, so a parent chaining off the reveal is not stranded. - First paint is blank. The stylesheet hides
split-text:not(:defined)so the text cannot flash in its finished pose and then drop back to animate — which means a prerendered page renders this text invisible until the module lands. Reserve the space for a headline above the fold, and don't wrap body copy that has to be readable before JavaScript. - Once it's done, it's ordinary text again. After the reveal the wrappers collapse to
display: contents, so the layout matches the original markup and the text reflows normally on resize.