Magnet Type

cursor-proximity axes

Per-word axis
variation.

npm ↗
GitHub ↗
TypeScriptZero dependenciesReact + Vanilla JS

CSS applies font-variation-settings to an entire element. Magnet Type applies them word by word or character by character — driven by cursor proximity. Words and characters inside the field attract toward a peak axis value; those outside hold at rest. Move your mouse through a paragraph and watch each word or letter respond independently.

Live demo — move your cursor through the text

Character mode active
Mode
Spread Radius80
Weight High900
Weight Low300

Character mode — per-character weight gradient across any block element. Works with mixed content (inline code, links, etc). Move your cursor through the paragraphs below.

Typography has always been a conversation between the reader and the page. Each word on a printed sheet is fixed — its weight locked at the moment of setting. But type on screen can breathe, respond, and shift its gravity as the cursor passes through.

Move your cursor slowly across the paragraphs. Characters nearest the cursor rise toward their peak weight, fading back as you move away. Compare the local weight gradient at different radii; the input is cursor position, not measured attention.

Character mode works per-character across any block element — including mixed content with inline code, links, or other elements. The weight gradient follows the cursor continuously, adjusted on scroll to refresh its position as the page moves.

spreadRadius controls how far from the cursor each character's weight fades to its minimum. Use proximityRadius to gate the effect to when the cursor is near the element edge, or omit it to always respond. Both props are independent and combinable.

How it works

The cursor field

Each word gets a span. Each update maps cursor distance to word centers, using cached positions by default. Words within the radius receive a font-variation-settings value interpolated between rest and peak — closer words get more of the peak value.

Attract and repel

In attract mode, nearby words approach the peak axis value and far words hold at rest. In repel mode, the logic inverts — words near the cursor stay at rest while words in the outer ring of the field approach peak. Each creates a different visual weight pattern.

Field mode vs legibility mode

Field mode runs a requestAnimationFrame loop driven by cursor position. The API mode named legibility applies fixed character treatments as the cursor comes near: I widens, l and 1 get heavier, 0 narrows while O widens, and an r before n or m gets a small gap. Letter-spacing compensates for width changes; check line wrapping with your font and sizes; at rest they are left exactly as the font draws them. The shape changes need wdth and wght axes; the r–n gap works in any font.

Performance via rAF batching

When its position cache needs rebuilding, the field loop reads word positions with getBoundingClientRect in a single batch pass, then writes all font-variation-settings in a second pass. This separates span reads from style writes. The loop is cancelled on unmount and restarted when options change.

Try a short heading with a loaded variable font and supported axis ranges. The legibility mode is an experimental visual treatment; reading and recognition improvements have not been established. Orientation input in the demo simulates pointer position and does not track eye gaze. Check line wrapping, contrast, and assistive technology behavior in your own layout. Reduced motion is checked on activation; character mode does not subscribe to changes while mounted.

Usage

TypeScript + React · Vanilla JS

Drop-in component

import { MagnetTypeText } from '@overpunch/magnettype'

<MagnetTypeText mode="word" axes={{ wght: [300, 600] }} radius={120}>
  Your paragraph text here...
</MagnetTypeText>

Hook — attach to any element

import { useMagnetType } from '@overpunch/magnettype'

const ref = useMagnetType({ mode: 'word', axes: { wght: [300, 600] }, radius: 120 })
<p ref={ref}>{children}</p>

Per-character component

import { MagnetChar } from '@overpunch/magnettype'

<MagnetChar minWeight={300} maxWeight={900} spreadRadius={80}>
  Your paragraph text here...
</MagnetChar>

Vanilla JS

import { startMagnetType, getCleanHTML } from '@overpunch/magnettype/core'

const el = document.querySelector('p')
const original = getCleanHTML(el) // capture original HTML before injection
const stop = startMagnetType(el, original, { axes: { wght: [300, 600] }, radius: 120 })
// call stop() to cancel the rAF loop and restore markup

Options

MagnetType options reference
OptionDefaultDescription
mode'word''word' — cursor proximity drives per-word font-variation-settings. 'legibility' — near the cursor, selected characters receive fixed width, weight, and spacing treatments (touch: while a finger drags over the text).
axes{ wght: [300, 500] }Map of axis tag → [restValue, peakValue]. restValue applies at full distance; peakValue when cursor is directly over the word.
radius120Pixel radius over which the field effect fades. Words beyond this distance receive restValue.
falloff'quadratic''linear' — strength decreases linearly with distance. 'quadratic' — decreases as distance², giving a tighter hot zone.
magnetMode'attract''attract' — words near cursor approach peakValue. 'repel' — words near cursor stay at restValue; far words approach peakValue.
scope'document''document' — listens for cursor events on the document (all instances share one field). 'element' — listens only within the element's own bounds.
cachePositionstrueCache word bounding rects after the first measurement pass. Eliminates repeated getBoundingClientRect calls during the active cursor loop; set to false if the layout shifts at runtime.
stabilizeLayouttrueApply compensating letter-spacing when axis values change to limit width changes as font weight shifts; verify wrapping with your font.
transitionMs0CSS transition duration in milliseconds applied when the cursor leaves the field. Adds a smooth ease-out rather than a snap back to restValue.
props—Additional proximity-driven effects via MagnetTypeProps. Accepts opacity: [rest, peak] to fade words by distance, and italic: true to italicise words as they enter the field.
wdthBoost30Legibility mode: wdth units for I and O (wider), 0 (narrower) and 1 (half).
wghtBoost200Legibility mode: wght units for l and 1 (heavier) and i (half).
trackBoost0.08Legibility mode: em of space after an r before n or m, taken back after it.

no-code

Use it in Webflow & Framer

The same effect, no build step — drop it straight into your design tool.

Webflow

One script tag, then mark any element with data-magnettype. Configure it with data-* attributes.

<!-- Site Settings → Custom Code → Footer, or an Embed element -->
<script src="https://cdn.jsdelivr.net/npm/@overpunch/magnettype/dist/magnettype.webflow.min.js"></script>

<!-- Then add data-magnettype to any text element -->
<h1 data-magnettype>Your headline</h1>

Framer

Insert → Code → New Component, then paste MagnetType.tsx ↗. It imports the core from esm.sh and exposes every option in the property panel — no build step.

import { /* core */ } from "https://esm.sh/@overpunch/magnettype"