What You'll Build

This tutorial walks you through creating a Neon Cursor Animation using HTML, CSS, and JavaScript powered by the Three.js Toys library. The result is a reactive glowing light trail that follows the user's mouse across the page — rendered in real time via WebGL for maximum smoothness and visual impact.

Each mouse movement generates a flowing neon stream that mimics illuminated light tubes. The design is perfectly suited for futuristic portfolios, tech demos, and any website inspired by synthwave or cyberpunk aesthetics.

💡 Quick Summary: The neonCursor() function from the threejs-toys CDN creates a fixed WebGL canvas behind your content. It listens to mousemove events and renders a flowing shader-based particle trail. Combine it with glowing text and a dark background for a high-tech look — no build tools needed.

Key Features of This Neon Cursor Effect

WebGL Light Trail
A shader-based particle system renders a smooth neon glow trail that follows cursor movement with physics-driven easing.
🎨
Fully Customizable
Tweak shaderPoints, radius1, radius2, colors, and motion smoothness via simple config parameters.
High Performance
Efficient WebGL rendering via Three.js keeps the animation at 60fps even with multiple glow segments active at once.
🌐
CDN Ready
The threejs-toys library loads from a CDN — no npm, no bundler, no build step. Add one script tag and it works.
🖥️
Full Viewport Canvas
The WebGL canvas is fixed and covers the full viewport using position: fixed so the glow effect spans every pixel of the screen.
🚀
Zero Build Tools
Pure HTML, CSS, and a single CDN script — open the file in any modern browser and the neon cursor runs instantly.

How It Works — Step by Step

Here's a breakdown of the three layers that power the neon cursor animation.

01

Structure the HTML

Start with a minimal page structure. A #app container holds the WebGL canvas generated by the Three.js Toys script. Text, headings, or logo elements sit above it using position: relative and a higher z-index. The canvas itself is injected automatically by the library into the DOM, so your HTML stays clean and simple. Use pointer-events: none on elements you want to pass mouse events straight through to the cursor tracker below.

02

Style with CSS

Set a dark background to maximize neon glow contrast — #000 or a deep navy works best. Apply position: fixed; inset: 0 to the canvas wrapper so the effect covers the full viewport without affecting page scroll. Add glowing text-shadow properties using cyan or magenta accent colors to match the cursor trail. Use pointer-events: none on the canvas container so clicks pass through to your actual page content below.

03

Configure the Neon Cursor Script

The core of the effect is a single neonCursor() call from the threejs-toys library. Pass a configuration object to control the visual behavior: shaderPoints sets the number of glow segments along the trail; curvePoints and curveLerp control path smoothness; radius1 and radius2 define inner glow thickness and outer spread; sleepTimeCoefX and sleepTimeCoefY adjust how the trail softens and fades when the cursor slows down. Set colors to any hex values to match your site's color palette.

04

Polish and Combine

The finished page pairs the neon trail with glowing text shadows, a centered layout, and a fully dark background. The result is a cyberpunk-style interactive interface where every mouse movement leaves a luminous streak of light. Performance stays high because WebGL handles all rendering — the DOM is never touched during animation, keeping everything smooth even on lower-powered hardware.

⚠️ Performance tip: Keep shaderPoints between 10–20 for the best balance of visual quality and frame rate. Very high values increase GPU load and may cause frame drops on older integrated graphics. Always test on a mid-range device before deploying to production.

Understanding the neonCursor() Configuration

The neonCursor() function accepts a single configuration object. The most impactful parameters are shaderPoints (number of glowing nodes along the trail), radius1 (inner glow size, controls the bright core), and radius2 (outer glow spread, controls the soft halo). curveLerp is a value between 0 and 1 that controls how tightly the trail follows the cursor — lower values create a lazy, flowing motion while higher values make the trail snap directly to cursor position.

Best Practices for Neon Cursor Pages

A neon cursor effect works best as an accent, not the main content. Keep surrounding UI elements minimal so the glow isn't competing with other visuals. Match the cursor trail color to your primary accent color using the colors config array. Ensure all text has sufficient contrast against the dark background — neon shadows on headings can add to the aesthetic without harming readability when kept subtle. For accessibility, provide a way to reduce motion using the prefers-reduced-motion media query to disable or simplify the effect.


Get the Source Code

The full source code is available for free on GitHub Gist. Explore the code below, copy it directly, or click Preview Result to see the live demo — then wait for the countdown to grab the full Gist link.

HTML — index.html
CSS — style.css
/* Loading source code... */
JS — script.js
// Loading source code...
💡 Quick Start: Download index.html, style.css, and script.js, place them in the same folder, and open index.html in your browser. The Three.js Toys library loads from a CDN automatically — no server or install step required.

Frequently Asked Questions

How does the neon cursor animation work?
The neonCursor() function from Three.js Toys creates a WebGL canvas fixed behind your page content. It tracks mousemove events and renders a flowing trail of shader-based particles along the cursor path. All rendering happens on the GPU via WebGL — the DOM is never touched during animation, keeping performance high.
Does the neon cursor effect work on mobile?
The default implementation uses mousemove events, which are desktop-only. On mobile, you can adapt it by replacing or supplementing the event listener with touchmove. WebGL support on modern smartphones is generally good, though performance varies on older devices — test before deploying on mobile-first projects.
Does this require any JavaScript frameworks or build tools?
No. The only dependency is the threejs-toys library, loaded via a single CDN script tag. Everything else is plain HTML and CSS. No npm, no Webpack, no React — just open the HTML file in any modern browser and the effect runs immediately.
Can I change the neon glow color?
Yes. Pass a colors array of hex values inside the neonCursor() configuration object. For example, colors: [0xff00cc, 0x00ffff] switches the trail from cyan to a magenta-cyan gradient. You can use any colors that complement your site's theme — just keep them bright against the dark background for maximum impact.
How do I prevent the cursor trail from blocking page interactions?
Set pointer-events: none on the WebGL canvas container using CSS. This passes all click and hover events through to your actual page content beneath the canvas. The Three.js Toys library typically handles this automatically, but it's good practice to confirm via DevTools that the canvas element has this style applied.

Conclusion

The Neon Cursor Animation is an elegant touch that blends motion and light into your web design. By using Three.js Toys, you can build this WebGL-powered effect with minimal code and maximum visual impact — a single configuration call generates a smooth, physics-based glow trail that reacts to every mouse movement.

Whether you're building a creative portfolio, a futuristic landing page, or an interactive art project, this glowing cursor gives your interface a pulse of energy that users notice and remember. Customize the colors, adjust the trail physics, and combine it with dark backgrounds and neon typography for a complete cyberpunk aesthetic.

Found this useful? Explore more HTML, CSS & JavaScript projects in the sidebar →