Magnetic Letters
betaText whose letters are pulled toward the pointer — or pushed away from it — and spring back home when it leaves.
- Effects & motion
- 1 file
- No extra npm packages
- Accessibility notes
Loading the example…
pnpm dlx @dowel-ui/cli add magnetic-lettersNo npm packages are needed beyond what Dowel already requires.
import { MagneticLetters } from "@/components/ui/magnetic-letters";Default
Repel
Wordmark
<MagneticLetters>
| Prop | Type | Default |
|---|---|---|
children (required)The text. Plain text: it is split into letters. | string | — |
asThe element to render. Default "span". | MagneticLettersElement | "span" |
modeLetters follow the pointer, or flee from it. Default "attract". | "attract" | "repel" | "attract" |
radiusHow far the pointer's pull reaches, in pixels. Default 140. | number | 140 |
scopeWhere to listen for the pointer: this text alone, or its parent. Default "parent". | "self" | "parent" | "parent" |
strengthThe furthest a letter moves, in pixels. Default 14. | number | 14 |
Plus every attribute of <span> except children.
The text is read as written: a visually hidden copy carries it and the letters are aria-hidden. The effect is decoration that needs a mouse, so it is off for touch and under reduced motion, where the text is simply text. It listens on its parent without capturing events, so nothing around it changes how it is used.
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes