StealThis .dev
Patterns Medium

Cursor Trail

Trail of dots that follow the cursor with decreasing opacity and size. Each point follows the previous with lerp interpolation, creating a smooth trailing effect.

Open in Lab
css javascript vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Cursor Trail

A mesmerizing trail of dots that chase the cursor across the screen. Each dot follows the one ahead of it using linear interpolation (lerp), producing a smooth, organic-feeling trail.

How it works

  1. An array of trail points is created, each represented by a small div
  2. On mousemove, the first point targets the cursor position
  3. Every subsequent point lerps toward the point ahead of it: pos += (target - pos) * ease
  4. A requestAnimationFrame loop updates all positions each frame
  5. Opacity and size decrease along the trail for a fading-tail effect

Customization

  • Count — number of trail dots
  • Size — base diameter of dots
  • Color — accent color with gradient falloff
  • Speed — lerp factor (lower = more lag, higher = tighter follow)

Use cases

  • Creative portfolio cursor effects
  • Interactive landing pages
  • Game UI cursor feedback