Liking cljdoc? Tell your friends :D

<x-kinetic-font>

A kinetic typography component that interpolates Variable Font axes (wght, wdth, slnt, opsz) using spring physics driven by cursor proximity or scroll velocity. Text physically bulges, leans, stretches, or breathes in response to user behavior, relying solely on the browser's 2D text rendering engine. CPU-only -- no Canvas, WebGL, or GPU required.

Tag

<x-kinetic-font text="Hello World" mode="bulge" trigger="cursor"></x-kinetic-font>

Attributes

AttributeTypeDefaultDescription
textstring""Text to display.
triggerenum"cursor"Force source: cursor, scroll, or both.
modetokens"bulge"Space-separated axis effects: bulge, lean, stretch, breathe.
per-charbooleanfalseWhen present, each character gets its own spring instance for spatial ripple effects.
massnumber1.0Spring mass. Range [0.1, 10]. Higher = slower, more inertia.
tensionnumber170.0Spring stiffness. Range [10, 500]. Higher = snappier.
frictionnumber26.0Spring damping. Range [1, 100]. Higher = less oscillation.
intensitynumber0.5Force multiplier. Range [0, 1]. Controls how far axes interpolate.
radiusnumber200.0Cursor proximity radius in pixels. Range [20, 1000].
font-familystring(inherit)Variable font family override.

Modes

Each mode maps to a Variable Font axis. Multiple modes can be combined.

ModeAxisRest ValueExcited ValueVisual Effect
bulgewght--*-weight-min--*-weight-maxText gets bolder/thicker
stretchwdth--*-width-min--*-width-maxText gets wider
leanslnt--*-slant-max--*-slant-minText tilts/italicises + CSS skewX transform for dramatic lean
breatheopsz--*-opsz-min--*-opsz-maxOptical size shifts

Example combining modes:

<x-kinetic-font text="Fluid" mode="bulge lean" trigger="cursor"></x-kinetic-font>

Properties (JS API)

PropertyTypeReflects Attribute
textstringtext
triggerstringtrigger
modestringmode
perCharbooleanper-char
massnumbermass
tensionnumbertension
frictionnumberfriction
intensitynumberintensity
radiusnumberradius
fontFamilystringfont-family

Events

EventDetailDescription
x-kinetic-font-spring-activate{}Fired when force is first applied and springs start moving.
x-kinetic-font-spring-settle{}Fired when all springs reach rest state.

CSS Custom Properties

PropertyDefaultDescription
--x-kinetic-font-colorcurrentColorText colour.
--x-kinetic-font-familysystem-ui, sans-serifVariable font family.
--x-kinetic-font-size2remFont size.
--x-kinetic-font-weight-min100wght axis rest value.
--x-kinetic-font-weight-max900wght axis excited value.
--x-kinetic-font-width-min75wdth axis rest value.
--x-kinetic-font-width-max125wdth axis excited value.
--x-kinetic-font-slant-min-12slnt axis excited value.
--x-kinetic-font-slant-max0slnt axis rest value.
--x-kinetic-font-opsz-min8opsz axis rest value.
--x-kinetic-font-opsz-max144opsz axis excited value.
--x-kinetic-font-skew-max-15Max CSS skewX angle (degrees) applied in lean mode. Set to 0 to disable.

CSS Parts

PartDescription
containerThe text container element.
charIndividual character span (per-char mode only).
sr-onlyScreen-reader-only text for accessibility.

Accessibility

  • Sets role="text" and aria-label with the plain text content.
  • Empty text sets aria-hidden="true".
  • A screen-reader-only element contains the full text.
  • Respects prefers-reduced-motion: reduce -- animation is disabled and font-variation-settings resets to normal.

Spring Physics

The component uses a damped spring model (semi-implicit Euler integration):

acceleration = (tension * (target - current) - friction * velocity) / mass
  • mass controls inertia: higher values make the spring respond more slowly.
  • tension controls stiffness: higher values make the spring snap back faster.
  • friction controls damping: higher values reduce oscillation.

The spring drives a scalar displacement (0-1) that is mapped to font axis ranges via linear interpolation.

Variable Font Requirements

This component requires a variable font loaded on the page. The font must support the axes used by your chosen modes. Common variable fonts:

  • Inter Variable -- supports wght, opsz, slnt
  • Recursive -- supports wght, slnt, CASL, CRSV, MONO
  • Roboto Flex -- supports wght, wdth, opsz, slnt, GRAD

If the font does not support an axis, that axis is silently ignored by the browser.

Usage Examples

Basic cursor proximity (bulge)

<x-kinetic-font text="Move your cursor here" mode="bulge" trigger="cursor"></x-kinetic-font>

Per-character ripple

<x-kinetic-font text="Ripple Effect" mode="bulge lean" trigger="cursor" per-char></x-kinetic-font>

Scroll-driven stretch

<x-kinetic-font text="Scroll Me" mode="stretch" trigger="scroll" intensity="0.8"></x-kinetic-font>

Custom spring parameters

<x-kinetic-font
  text="Bouncy"
  mode="bulge"
  trigger="cursor"
  mass="0.5"
  tension="300"
  friction="10"
></x-kinetic-font>

Custom axis ranges via CSS

x-kinetic-font {
  --x-kinetic-font-family: "Roboto Flex", sans-serif;
  --x-kinetic-font-weight-min: 300;
  --x-kinetic-font-weight-max: 700;
  --x-kinetic-font-size: 3rem;
}

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close