In November 2016 I rounded up five snow effects for your website, finished on a blizzard, and asked a question I assumed nobody would ever answer: "What could go wrong?"
Ten years later, I'd like to answer it myself.
The fellowship of the flake
The good news first: all five demos are still on CodePen. Ten years is a few lifetimes on the web, and I fully expected a page of broken embeds.
Loktar's "Its snowing!" had snow that dodged your cursor. Mine, "CSS Falling Snow", stacked layers of flakes for a bit of depth. pimskie's "Snow" did distant, blurry snowstorms. Neave Interactive's "Happy Xmas!" let you steer the wind with your mouse. And Tiffany Rayside's "Midnight Snow" was the blizzard, because we were never going to stop at a gentle flurry.
Look under the bonnet and they split neatly. Three draw every flake onto a canvas with JavaScript, redrawing the whole scene dozens of times a second. Neave's moves real page elements around in 3D, steered by your mouse. Mine was the odd one out: layers of snow images, moved with nothing but CSS. Whether that was foresight or laziness, I'll let you decide.
All five are still lovely. They also share one gap, and it's where the web has moved on most.
What's changed
None of them checks whether you'd rather not see things move. That's no criticism of anyone: in 2016 a website had no way to ask. The prefers-reduced-motion setting arrived in Safari in 2017 and had reached the other major browsers by 2020. Now anyone who finds motion makes them dizzy can say so once, in their device settings, and every website can listen.
One does not simply stick a blizzard on a website. The accessibility guidelines have asked for an off switch since 2008: anything that moves by itself for more than five seconds, alongside other content, needs a way to pause, stop or hide it. In 2016 I recommended a blizzard with no off switch. In my defence, it was very festive.
I also care far more about weight than I used to. Every byte of a festive joke has to travel to someone's phone, often on a train, for something that's only up for a month. So I set myself a brief: every good idea from the five, in as few bytes as possible.
One script to rule them all
The 2016 post ended with a four-step plan:
- Choose your snow
- Add the code
- ???
- PROFIT
The 2026 version skips step one, because you no longer have to choose.
Each of the five lends it one idea:
- Depth, from my layers: every flake gets a distance, and nearer flakes are bigger, brighter and faster.
- Softness, from pimskie's snowstorm: one blurry flake is drawn once and stamped everywhere, so the blur comes free.
- Wind, from Neave: move your mouse left or right and the snow leans with it.
- Dodging, from Loktar: flakes swerve around your cursor.
- The blizzard, from Tiffany Rayside: hold your mouse down, or your finger on a phone, and the sky turns into Caradhras.
It's one script, with no HTML or CSS to add. It builds its own canvas and its own off switch, so you can paste it into any site's footer. And yes, after all that about my CSS, it draws on a canvas. Dodging and steering need JavaScript to know where every flake is, and one canvas is the lightest way to give it that.
(() => {
const motion = matchMedia('(prefers-reduced-motion: reduce)');
if (new Date().getMonth() !== 11 || motion.matches) return;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const button = document.createElement('button');
canvas.setAttribute('aria-hidden', true);
canvas.style.cssText = 'position:fixed;inset:0;width:100%;height:100%;pointer-events:none;z-index:10';
button.style.cssText = 'position:fixed;right:1rem;bottom:1rem;z-index:11';
button.textContent = 'Stop the snow';
document.body.append(canvas, button);
// One soft flake, drawn once and stamped everywhere
const sprite = document.createElement('canvas');
sprite.width = sprite.height = 16;
const s = sprite.getContext('2d');
const glow = s.createRadialGradient(8, 8, 0, 8, 8, 8);
glow.addColorStop(0, '#fff');
glow.addColorStop(1, '#fff0');
s.fillStyle = glow;
s.fillRect(0, 0, 16, 16);
let width, height, frame, mouse, gusting, wind = 0, storm = 1, spares = 0, until = 0;
const resize = () => {
width = canvas.width = innerWidth;
height = canvas.height = innerHeight;
};
resize();
// z is depth: near flakes are bigger, brighter and faster.
// Only 150 fall normally. The other 300 are spares.
const flakes = Array.from({ length: 450 }, (_, i) => ({
x: Math.random() * width,
y: Math.random() * height,
z: Math.random(),
spare: i >= 150,
}));
const draw = () => {
const blizzard = Date.now() < until;
wind += ((mouse ? (mouse.clientX / width - 0.5) * 3 : 0) - wind) * 0.02;
storm += ((gusting ? 4 : blizzard ? 3 : 1) - storm) * 0.05;
spares += ((blizzard ? 1 : 0) - spares) * 0.05;
ctx.clearRect(0, 0, width, height);
for (const f of flakes) {
const show = f.spare ? spares : 1;
if (show < 0.01) continue;
const size = 2 + f.z * 10;
f.y += (0.4 + f.z) * storm;
f.x += wind * f.z * storm;
if (mouse) {
const dx = f.x - mouse.clientX;
const dy = f.y - mouse.clientY;
const d = Math.hypot(dx, dy);
if (d && d < 80) {
f.x += (dx / d) * (80 - d) * 0.1;
f.y += (dy / d) * (80 - d) * 0.1;
}
}
if (f.y > height + size) {
f.y = -size;
f.x = Math.random() * width;
}
if (f.x > width + size) f.x = -size;
if (f.x < -size) f.x = width + size;
ctx.globalAlpha = (0.3 + f.z * 0.7) * show;
ctx.drawImage(sprite, f.x - size / 2, f.y - size / 2, size, size);
}
frame = requestAnimationFrame(draw);
};
const stop = () => {
cancelAnimationFrame(frame);
canvas.hidden = true;
button.textContent = 'Let it snow';
};
button.onclick = () => {
if (canvas.hidden) {
canvas.hidden = false;
button.textContent = 'Stop the snow';
draw();
} else {
stop();
}
};
// One more thing
const konami = 'arrowup arrowup arrowdown arrowdown arrowleft arrowright arrowleft arrowright b a enter';
let typed = '';
addEventListener('keydown', (e) => {
if (e.key === 'Shift') return;
typed = (typed + ' ' + e.key).toLowerCase().slice(-konami.length);
if (typed === konami) until = Date.now() + 5000;
});
motion.onchange = () => motion.matches && stop();
addEventListener('resize', resize);
addEventListener('pointermove', (e) => (mouse = e));
document.documentElement.addEventListener('pointerleave', () => (mouse = null));
addEventListener('pointerdown', () => (gusting = true));
addEventListener('pointerup', () => (gusting = false));
addEventListener('pointercancel', () => (gusting = false));
draw();
})();The five 2016 pens run to about 14KB of code between them, before you count the snow images mine leans on. This does all five tricks, plus one more I'll come to, in 3.6KB as written and about 1KB once it's minified and gzipped. My precious.
It only snows in December. The script checks the month, so the snow arrives on 1 December and leaves on 1 January. It's the only feature I've ever built that removes itself without a ticket.
Reduced motion gets respected twice. The script won't start for anyone who has asked their device for less motion, and it stops if they switch that setting on halfway through a visit.
Gandalf would hate it: everything shall pass. pointer-events: none lets every click fall straight through to the page underneath, and aria-hidden saves screen readers from describing the weather.
It's already snowing when the page loads. Every flake starts somewhere random on the screen, so nobody sees an empty sky followed by 150 flakes setting off together like a synchronised swimming team.
And there's an off switch: a real button, with real words on it, fixed in the corner where it's always within reach. Switching it off stops the animation completely rather than just hiding it, and browsers already pause it when the tab's in the background, so the snow only costs anything while someone's watching.
Now make it yours
The whole thing is on CodePen, next to its 2016 ancestor, if you'd rather fork it than copy it. A demo switch lets it snow all year round there. Once it works, play with it. Draw a ❄ into the flake instead of a soft blur. Slow it right down for a gentle Sunday flurry. Make it fall upwards on New Year's Eve and call it fireworks. The rules keep it kind. They don't have to keep it boring.
What could go wrong
Ten years ago I asked what could go wrong. Quite a lot, it turns out, mostly for anyone who gets motion sick and anyone trying to click a link through a blizzard.
But the instinct was right. The web is better for having a few things on it that exist purely to make someone smile in December. Build one this year. Just give it an off switch.
One more thing
In my early days as a web developer, I added a script to most of the websites I built. If you typed the Konami code, the site would do something. Up, up, down, down, left, right, left, right, B, A, with Enter standing in for the traditional Start.
So it only felt fitting to carry on the tradition. If you read the script properly, you might have spotted it already. Type the code while it's snowing and you get a proper blizzard: three times the snow, falling three times as fast, for five seconds. Then it settles back down as if nothing happened.
Try it on the CodePen above. Click into it first so it's listening. And yes, the off switch still works. I've learnt something in ten years.