Fluid Cursor Trail for React

Canvas particle trail that follows the cursor. Fixed overlay, customizable color, physics, and particle count.

Component

Decorative cursor trail

Move your cursor here - trail appears in this area only

Installation

 

Usage

Import

Add the FluidCursorTrail import.

import { FluidCursorTrail } from "@/components/fluid-cursor-trail";

Use

Add to layout for site-wide effect.

<FluidCursorTrail />;

Guidelines

  • bound=false (default): full-screen fixed overlay. Add to root layout for site-wide effect.
  • bound=true: trail limited to parent container. Parent needs position: relative; use absolute inset-0 on the wrapper.
  • velocity: initial particle spread. gravity: downward acceleration. fadeSpeed: opacity decay per frame.

Props

All props are optional unless marked required. Use these to customize every aspect of the component.

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the canvas.
colorstring"#8b5cf6"Particle color (hex or CSS color).
particleCountnumber3Particles spawned per mousemove.
particleSizenumber4Particle radius in pixels.
velocitynumber4Initial particle velocity spread.
gravitynumber0.2Downward gravity applied each frame.
fadeSpeednumber0.02Opacity decrease per frame (fade speed).
zIndexnumber9999z-index of the overlay.
boundbooleanfalseWhen true, trail is limited to the parent container instead of full screen.

Accessibility

  • Decorative visual effect with no interactive controls, no focusable elements, and no keyboard interaction to support.
  • The canvas is pointer-events none and carries only a title attribute plus fallback text, so it adds no operable UI and is effectively invisible to keyboard and assistive technology.
  • It does not check prefers-reduced-motion, so the animation runs unconditionally; it should be guarded with matchMedia('(prefers-reduced-motion: reduce)') to disable or reduce particles for users who prefer reduced motion.
  • As a non-essential ambient layer it conveys no information, so the lack of ARIA roles or labels is acceptable, but motion-sensitive users currently have no built-in way to opt out.

Performance

  • The effect renders into a Canvas 2D context, clearing and redrawing every particle with arc and fill each frame rather than animating CSS transform or opacity, so cost scales with particle count and is CPU rasterization rather than a cheap GPU-composited property.
  • The render loop uses requestAnimationFrame and prunes dead particles into a fresh array each frame, which keeps the loop bounded but offers no throttling when particleCount or fadeSpeed produces many simultaneous particles.
  • There is no will-change hint or GPU compositing of the canvas, and the canvas is sized to the full viewport or the bound container via resize handling.
  • A ResizeObserver is used only in bound mode and the mousemove and resize listeners plus the rAF loop are all cleaned up on unmount, avoiding leaked listeners and timers.
  • It has no IntersectionObserver or visibility gating, so the animation keeps running even when offscreen or when the user prefers reduced motion.

Examples

Basic

Add to layout for site-wide cursor trail.

Decorative cursor trail

Move your cursor here - trail appears in this area only

import { FluidCursorTrail } from "@/components/fluid-cursor-trail";

export default function Layout({ children }) {
  return (
    <>
      {children}
      <FluidCursorTrail />
    </>
  );
}

Bound to container

Trail limited to container. Use bound with a relative parent.

Decorative cursor trail

Move your cursor here - trail appears in this area only

import { FluidCursorTrail } from "@/components/fluid-cursor-trail";

<div className="relative h-64">
  <FluidCursorTrail bound />
  <div className="relative flex h-full items-center justify-center">
    Content
  </div>
</div>;

Full screen

Full-screen trail with custom color and particle settings.

Decorative cursor trail

Move your cursor here - trail appears in this area only

import { FluidCursorTrail } from "@/components/fluid-cursor-trail";

<FluidCursorTrail
  color="#10b981"
  particleCount={5}
  particleSize={6}
/>;

Physics & layering

Faster particles, stronger gravity, quicker fade, custom z-index.

Decorative cursor trail

Move your cursor here - trail appears in this area only

import { FluidCursorTrail } from "@/components/fluid-cursor-trail";

<FluidCursorTrail
  color="#f43f5e"
  velocity={8}
  gravity={0.3}
  fadeSpeed={0.03}
  zIndex={50}
/>;

Last updated on Jun 19

Made with ❤️ by Pulkit &

© 2026 Pulkit. All rights reserved

Last updated: