<TextMorph />

Text continuity for interfaces on the web.

Options

Every component takes the same options. In React, Vue and Svelte they're props (class for className in Vue and Svelte). In plain JavaScript they go to new TextMorph({ ... }).

OptionDefaultWhat it does
children / textThe text to show. In React, a number is formatted for you.
duration400How long a morph takes, in milliseconds. Ignored when ease is a spring.
ease"cubic-bezier(0.19, 1, 0.22, 1)"A CSS easing, or spring parameters.
pluginsclassic()How text is cut up and how it moves. See using plugins.
locale"en"For splitting text into words and letters, and for formatting numbers.
decimalsFraction digits for a numeric value. Ignored for strings.
disabledfalseSwap text without animating.
respectReducedMotiontrueSwap text without animating when the user prefers reduced motion.
debugfalseShow the boxes torph moves, and check plugins.
onAnimationStartCalled when a morph begins.
onAnimationCompleteCalled when a morph finishes.
onAnimationCancelCalled when the next morph interrupts this one. Each morph calls exactly one of this and onAnimationComplete.
as"span"The element to render.
className, stylePassed to the element.

Springs

Pass spring parameters to ease for physics-based motion. The spring decides how long it takes, so duration is ignored.

<TextMorph ease={{ stiffness: 200, damping: 20 }}>{text}</TextMorph>
ParameterDefaultWhat it does
stiffness100How hard the spring pulls.
damping10How quickly it stops bouncing.
mass1How heavy the moving text is.
precision0.001How close to rest counts as settled.

Multi-line text

A newline in the value is a line break, and text morphs across lines like anywhere else.

<TextMorph>{"Design it.\nBuild it.\nShip it."}</TextMorph>

Text matching

The matching torph runs on is exported, for building your own behaviour on top of it:

  • segmentText(value, locale) splits a value into segments.
  • diffSegments(oldSegments, newText, locale) matches a new value against old segments, and returns what persists, enters and exits.