How to Create a Section-Based Themed Cursor Trail in Webflow
Learn how to create a cursor whose trail changes color depending on the section of the page in Webflow.
In this tutorial, Sandro, cofounder of the Gemeos Webflow agency, shows you how to create a cursor trail whose colors change depending on the section of the page in Webflow.
Example
Change the theme, then move your mouse in the area
Active theme: fire
| Theme | Colors | Custom attribute |
|---|---|---|
| fire (default) | Orange, red, gold | data-cursor-theme='fire' |
| water | Blue, cyan, sky | data-cursor-theme='water' |
| nature | Green, emerald | data-cursor-theme='nature' |
1. Add the attribute to your sections
On every Webflow section where you want a different theme, add the custom attribute data-cursor-theme with the value fire, water, or nature. The script automatically detects which section is centered on the screen.
2. Add the script in Footer code
(function() {
if (!window.matchMedia('(pointer: fine)').matches) return;
var COUNT = 15;
var particles = [];
var mouseX = 0, mouseY = 0;
// Detect the active section to change the theme
function getTheme() {
var sections = document.querySelectorAll('[data-cursor-theme]');
var active = 'fire';
sections.forEach(function(s) {
var rect = s.getBoundingClientRect();
if (rect.top <= window.innerHeight / 2 && rect.bottom >= window.innerHeight / 2) {
active = s.dataset.cursorTheme;
}
});
return active;
}
var themes = {
fire: ['#ff4500','#ff6a00','#ffb347','#ff8c00','#ffd700'],
water: ['#00bfff','#1e90ff','#87ceeb','#4169e1','#00ced1'],
nature:['#22c55e','#4ade80','#86efac','#16a34a','#bbf7d0'],
};
for (var i = 0; i < COUNT; i++) {
var p = document.createElement('div');
p.style.cssText = 'position:fixed;pointer-events:none;border-radius:50%;z-index:9999;transition:opacity 0.4s;opacity:0;';
document.body.appendChild(p);
particles.push({ el: p, x: 0, y: 0, life: 0 });
}
document.addEventListener('mousemove', function(e) {
mouseX = e.clientX; mouseY = e.clientY;
var theme = getTheme();
var colors = themes[theme] || themes.fire;
var p = particles[Math.floor(Math.random() * COUNT)];
var size = 6 + Math.random() * 8;
var color = colors[Math.floor(Math.random() * colors.length)];
p.el.style.width = size + 'px';
p.el.style.height = size + 'px';
p.el.style.background = color;
p.el.style.left = mouseX + 'px';
p.el.style.top = mouseY + 'px';
p.el.style.opacity = '0.8';
p.el.style.boxShadow = '0 0 6px ' + color;
setTimeout(function() { p.el.style.opacity = '0'; }, 150);
});
})();3. Add your own theme
Add an entry to the themes object with your brand colors:
var themes = {
fire: ['#ff4500','#ff6a00','#ffd700'],
water: ['#00bfff','#1e90ff','#87ceeb'],
nature: ['#22c55e','#4ade80','#86efac'],
brand: ['#a78bfa','#f472b6','#60a5fa'], // Your custom colors
};Conclusion
A themed cursor adds a narrative layer to navigation. Use cases:
- Creative websites with distinct themed sections
- Agency portfolios with transitions between projects
- Storytelling landing pages with multiple acts
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.














