Rain
import { useState } from 'react';
// 24 drops on fixed lanes and phases; the heavier the rain, the more of them fall.
const DROPS = Array.from({ length: 24 }, (_, k) => ({ k, x: 6 + ((k * 53) % 186), d: -Number(((k * 0.37) % 1).toFixed(2)) }));
const RIPPLES = [{ x: 46, d: 0 }, { x: 118, d: -0.6 }, { x: 160, d: -1.1 }, { x: 82, d: -0.3 }];
const css = `
.slider-rain { display: grid; justify-items: center; gap: 12px; width: 220px; }
@keyframes slider-rain-fall { from { transform: translateY(-20px) rotate(12deg); } to { transform: translateY(96px) rotate(12deg); } }
@keyframes slider-rain-ripple { from { transform: scale(0.2); opacity: 0.9; } to { transform: scale(1.6); opacity: 0; } }
.slider-rain__air { position: relative; width: 200px; height: 104px; overflow: hidden; border-radius: 12px; background: linear-gradient(light-dark(#ebedf0, #232529), light-dark(#f3f4f7, #1a1c1f)); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.slider-rain__drop { position: absolute; top: 0; width: 1.5px; height: 12px; border-radius: 1px; background: linear-gradient(transparent, light-dark(#42454c, #e5e6e9)); opacity: clamp(0, calc((var(--slider-rain-v) * 24 - var(--k)) * 1.5), 0.9); animation: slider-rain-fall calc(0.9s - var(--slider-rain-v) * 0.35s) linear infinite var(--d); }
.slider-rain__puddle { position: absolute; left: 10px; right: 10px; bottom: 6px; height: 10px; border-radius: 50%; background: color-mix(in oklab, light-dark(#5f626a, #a7abb2) calc(20% + var(--slider-rain-v) * 30%), transparent); transform: scaleX(calc(0.4 + var(--slider-rain-v) * 0.6)); transition: transform 0.5s; }
.slider-rain__ripple { position: absolute; bottom: 7px; width: 18px; height: 6px; margin-left: -9px; border-radius: 50%; border: 1px solid light-dark(#50535b, #c6c8cd); opacity: 0; animation: slider-rain-ripple 1.6s ease-out infinite var(--d); visibility: hidden; }
.slider-rain[data-wet] .slider-rain__ripple { visibility: visible; }
@media (prefers-reduced-motion: reduce) {
.slider-rain__drop, .slider-rain__ripple { animation: none; }
.slider-rain__drop { transform: translateY(40px) rotate(12deg); }
}
.slider-rain__read { color: light-dark(#50535b, #c6c8cd); font-size: 12px; font-variant-numeric: tabular-nums; }
.slider-rain__read b { color: light-dark(#373a40, #f1f2f3); font-weight: 600; }
.slider-rain__track { position: relative; width: 100%; height: 24px; }
.slider-rain__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-rain__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(10px + var(--slider-rain-v) * (100% - 20px)); background: light-dark(#50535b, #c6c8cd); }
.slider-rain__thumb { position: absolute; top: 2px; left: calc(var(--slider-rain-v) * (100% - 20px)); width: 20px; height: 20px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-rain:has(.slider-rain__input:focus-visible) .slider-rain__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-rain__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-rain__input::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; }
.slider-rain__input::-moz-range-thumb { width: 20px; height: 20px; border: 0; }
`;
export function RainSlider() {
const [v, setV] = useState(12);
const t = (v - 0) / (40 - 0);
const word = v === 0 ? 'Dry' : v < 3 ? 'Drizzle' : v < 10 ? 'Light rain' : v < 25 ? 'Moderate rain' : 'Heavy rain';
return (
<>
<style>
{css}
</style>
<div className="slider-rain" style={{ '--slider-rain-v': t } as React.CSSProperties} data-wet={v > 0 || undefined}>
<div className="slider-rain__air" aria-hidden="true">
{DROPS.map((d) => (
<span key={d.k} className="slider-rain__drop" style={{ left: d.x, '--k': d.k, '--d': `${d.d}s` } as React.CSSProperties} />
))}
<span className="slider-rain__puddle" />
{RIPPLES.map((r) => (
<span key={r.x} className="slider-rain__ripple" style={{ left: r.x, '--d': `${r.d}s` } as React.CSSProperties} />
))}
</div>
<span className="slider-rain__read" aria-hidden="true">
<b>{v} mm/h</b> · {word}
</span>
<div className="slider-rain__track">
<span className="slider-rain__rail" />
<span className="slider-rain__fill" />
<span className="slider-rain__thumb" />
<input
className="slider-rain__input"
type="range"
min={0}
max={40}
value={v}
onChange={(e) => setV(+e.target.value)}
aria-label="Rainfall"
aria-valuetext={`${v} millimetres an hour, ${word.toLowerCase()}`}
/>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initSliderRain(el) on the mounted element instead.
<div class="slider-rain" style="--slider-rain-v:0.3" data-wet="true">
<div class="slider-rain__air" aria-hidden="true">
<span class="slider-rain__drop" style="left:6px;--k:0;--d:0s"></span>
<span class="slider-rain__drop" style="left:59px;--k:1;--d:-0.37s"></span>
<span class="slider-rain__drop" style="left:112px;--k:2;--d:-0.74s"></span>
<span class="slider-rain__drop" style="left:165px;--k:3;--d:-0.11s"></span>
<span class="slider-rain__drop" style="left:32px;--k:4;--d:-0.48s"></span>
<span class="slider-rain__drop" style="left:85px;--k:5;--d:-0.85s"></span>
<span class="slider-rain__drop" style="left:138px;--k:6;--d:-0.22s"></span>
<span class="slider-rain__drop" style="left:191px;--k:7;--d:-0.59s"></span>
<span class="slider-rain__drop" style="left:58px;--k:8;--d:-0.96s"></span>
<span class="slider-rain__drop" style="left:111px;--k:9;--d:-0.33s"></span>
<span class="slider-rain__drop" style="left:164px;--k:10;--d:-0.7s"></span>
<span class="slider-rain__drop" style="left:31px;--k:11;--d:-0.07s"></span>
<span class="slider-rain__drop" style="left:84px;--k:12;--d:-0.44s"></span>
<span class="slider-rain__drop" style="left:137px;--k:13;--d:-0.81s"></span>
<span class="slider-rain__drop" style="left:190px;--k:14;--d:-0.18s"></span>
<span class="slider-rain__drop" style="left:57px;--k:15;--d:-0.55s"></span>
<span class="slider-rain__drop" style="left:110px;--k:16;--d:-0.92s"></span>
<span class="slider-rain__drop" style="left:163px;--k:17;--d:-0.29s"></span>
<span class="slider-rain__drop" style="left:30px;--k:18;--d:-0.66s"></span>
<span class="slider-rain__drop" style="left:83px;--k:19;--d:-0.03s"></span>
<span class="slider-rain__drop" style="left:136px;--k:20;--d:-0.4s"></span>
<span class="slider-rain__drop" style="left:189px;--k:21;--d:-0.77s"></span>
<span class="slider-rain__drop" style="left:56px;--k:22;--d:-0.14s"></span>
<span class="slider-rain__drop" style="left:109px;--k:23;--d:-0.51s"></span>
<span class="slider-rain__puddle"></span>
<span class="slider-rain__ripple" style="left:46px;--d:0s"></span>
<span class="slider-rain__ripple" style="left:118px;--d:-0.6s"></span>
<span class="slider-rain__ripple" style="left:160px;--d:-1.1s"></span>
<span class="slider-rain__ripple" style="left:82px;--d:-0.3s"></span>
</div>
<span class="slider-rain__read" aria-hidden="true"><b>12 mm/h</b> · Moderate rain</span>
<div class="slider-rain__track">
<span class="slider-rain__rail"></span>
<span class="slider-rain__fill"></span>
<span class="slider-rain__thumb"></span>
<input class="slider-rain__input" type="range" min="0" max="40" aria-label="Rainfall" aria-valuetext="12 millimetres an hour, moderate rain" value="12"/>
</div>
</div>.slider-rain { display: grid; justify-items: center; gap: 12px; width: 220px; }
@keyframes slider-rain-fall { from { transform: translateY(-20px) rotate(12deg); } to { transform: translateY(96px) rotate(12deg); } }
@keyframes slider-rain-ripple { from { transform: scale(0.2); opacity: 0.9; } to { transform: scale(1.6); opacity: 0; } }
.slider-rain__air { position: relative; width: 200px; height: 104px; overflow: hidden; border-radius: 12px; background: linear-gradient(light-dark(#ebedf0, #232529), light-dark(#f3f4f7, #1a1c1f)); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.slider-rain__drop { position: absolute; top: 0; width: 1.5px; height: 12px; border-radius: 1px; background: linear-gradient(transparent, light-dark(#42454c, #e5e6e9)); opacity: clamp(0, calc((var(--slider-rain-v) * 24 - var(--k)) * 1.5), 0.9); animation: slider-rain-fall calc(0.9s - var(--slider-rain-v) * 0.35s) linear infinite var(--d); }
.slider-rain__puddle { position: absolute; left: 10px; right: 10px; bottom: 6px; height: 10px; border-radius: 50%; background: color-mix(in oklab, light-dark(#5f626a, #a7abb2) calc(20% + var(--slider-rain-v) * 30%), transparent); transform: scaleX(calc(0.4 + var(--slider-rain-v) * 0.6)); transition: transform 0.5s; }
.slider-rain__ripple { position: absolute; bottom: 7px; width: 18px; height: 6px; margin-left: -9px; border-radius: 50%; border: 1px solid light-dark(#50535b, #c6c8cd); opacity: 0; animation: slider-rain-ripple 1.6s ease-out infinite var(--d); visibility: hidden; }
.slider-rain[data-wet] .slider-rain__ripple { visibility: visible; }
@media (prefers-reduced-motion: reduce) {
.slider-rain__drop, .slider-rain__ripple { animation: none; }
.slider-rain__drop { transform: translateY(40px) rotate(12deg); }
}
.slider-rain__read { color: light-dark(#50535b, #c6c8cd); font-size: 12px; font-variant-numeric: tabular-nums; }
.slider-rain__read b { color: light-dark(#373a40, #f1f2f3); font-weight: 600; }
.slider-rain__track { position: relative; width: 100%; height: 24px; }
.slider-rain__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-rain__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(10px + var(--slider-rain-v) * (100% - 20px)); background: light-dark(#50535b, #c6c8cd); }
.slider-rain__thumb { position: absolute; top: 2px; left: calc(var(--slider-rain-v) * (100% - 20px)); width: 20px; height: 20px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-rain:has(.slider-rain__input:focus-visible) .slider-rain__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-rain__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-rain__input::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; }
.slider-rain__input::-moz-range-thumb { width: 20px; height: 20px; border: 0; }function initSliderRain(root) {
var input = root.querySelector('.slider-rain__input');
var read = root.querySelector('.slider-rain__read');
function update() {
var v = +input.value;
var t = (v - 0) / (40 - 0);
root.style.setProperty('--slider-rain-v', t);
var word = v === 0 ? 'Dry' : v < 3 ? 'Drizzle' : v < 10 ? 'Light rain' : v < 25 ? 'Moderate rain' : 'Heavy rain';
root.toggleAttribute('data-wet', v > 0);
read.innerHTML = '<b>' + v + ' mm/h</b> · ' + word;
input.setAttribute('aria-valuetext', v + ' millimetres an hour, ' + word.toLowerCase());
}
input.addEventListener('input', update);
update();
return function () { input.removeEventListener('input', update); };
}
document.querySelectorAll('.slider-rain').forEach(initSliderRain);Goal: Create a "Rain" slider.
Visual behavior: A rainfall slider: more and more drops fall as the rate rises, the puddle spreads and ripples ring out on it, from a drizzle to a downpour.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each of 24 drops has an index (--k) and fades in with clamp(0, (value * 24 - index) * 1.5, 0.9), so heavier rain means more drops.
- The drops fall on a loop with fixed negative delays, so they are already mid-fall on load; ripples on the puddle run only while it is raining (data-wet).
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the drops and ripples hold still.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Rain" slider.
Visual behavior: A rainfall slider: more and more drops fall as the rate rises, the puddle spreads and ripples ring out on it, from a drizzle to a downpour.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each of 24 drops has an index (--k) and fades in with clamp(0, (value * 24 - index) * 1.5, 0.9), so heavier rain means more drops.
- The drops fall on a loop with fixed negative delays, so they are already mid-fall on load; ripples on the puddle run only while it is raining (data-wet).
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the drops and ripples hold still.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
A rainfall slider: more and more drops fall as the rate rises, the puddle spreads and ripples ring out on it, from a drizzle to a downpour.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- state change, continuous, loop
- Techniques
- css variables, keyframes, stagger
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the drops and ripples hold still.