Skip to content

Cursor Trail Effect

A chain of glowing dots that follows the mouse or finger and fades out behind it, with glow, rainbow and ring styles and an idle animation.

Also known as: mouse trail effect, glowing cursor trail, cursor follower dots, mouse follow animation, rainbow cursor trail

Cursor Trail Effect live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A cursor trail effect made with CSS and a small vanilla JavaScript loop: a chain of dots follows the mouse or a finger across a dark panel and fades out behind it. Three styles (glow, rainbow and rings) can be switched with a segmented control. Use it on a landing page hero, a portfolio intro or a playful 404 page.

How it works

The root section.ct-stage holds an empty .ct-layer for the dots and the .ct-content with the heading, text and .ct-modes buttons. On DOMContentLoaded the script creates as many span.ct-dot elements as data-ct-dots asks for and gives each one the custom properties --ct-i (its index) and --ct-n (the total). CSS uses them for the fade: opacity and the color mix shrink toward the tail.

A requestAnimationFrame loop moves the chain. The first dot eases toward the pointer, and every following dot eases toward the dot in front of it, which creates the smooth tail. The script listens for pointermove and pointerleave on the stage, so mouse, pen and touch all work. While no pointer is over the panel, the head follows a figure-eight path, so the effect is visible on first load and in screenshots.

The style lives in data-ct-mode on .ct-stage. Each .ct-mode button sets it from its data-ct-set value, and the CSS attribute selectors restyle the dots: glow blends --ct-accent into --ct-accent-2 with a halo, rainbow shifts the hue per dot, and rings draws hollow circles that grow along the trail.

Customization

  • data-ct-dots on .ct-stage: number of dots, e.g. 30 for a longer tail.
  • data-ct-mode: the starting style (glow, rainbow or rings); update aria-pressed on the buttons to match.
  • --ct-size on .ct-stage: diameter of the lead dot.
  • --ct-accent and --ct-accent-2: the two colors of the glow trail, the title gradient and the active button.
  • --ct-height: minimum height of the panel.
  • FOLLOW at the top of script.js: lower values such as 0.2 give a longer, lazier trail; higher values keep the dots tight.
  • Edit idleTarget() to change the path the trail draws when the pointer is away.

Use cases

  • Landing page heroes: a glowing chain of dots follows the pointer across a dark panel
  • Portfolio intros: switch between glow, rainbow and ring styles for a playful first impression
  • 404 pages: a playful effect gives a missing page some personality
  • Touch devices: the trail follows a finger as well as a mouse, with an idle animation when nobody is moving
  • Creative agency sites: add a decorative effect that never blocks clicks

Accessibility

The dots are purely decorative: .ct-layer is aria-hidden="true" and has pointer-events: none, so it never blocks clicks. The section is labelled by its heading, and the style switcher is a role="group" of real buttons using aria-pressed, with a visible focus outline. With prefers-reduced-motion: reduce the script does not start the animation loop and CSS hides the layer, leaving a static panel.

Usage notes

Several stages can share a page; each one creates its own dots and loop. To use the effect on a whole page, give .ct-stage the full viewport size or move the layer to a fixed overlay.

Cursor Trail Effect at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Cursor Effects
License
Free for personal and commercial use

Questions about this template

Can I use the Cursor Trail Effect code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Cursor Trail Effect – Pure CSS cursor effects component screenshot
Cursor Trail Effect · Pure CSS Cursor Effects

More Cursor Effects

Custom Cursor Follower – Pure CSS cursor effects preview

Custom Cursor Follower

Smooth custom cursor with a dot and an eased ring that grows on links, shows a label over cards and inverts the headline, in CSS and vanilla JS.

Image Reveal Cursor on Hover – Tailwind CSS cursor effects preview

Image Reveal Cursor on Hover

Tailwind CSS project list where hovering a row reveals a photo that follows the cursor with smooth easing and tilt, plus keyboard and touch fallbacks.