A sea of dots on a 3D plane rolling in slow waves to the horizon, swelling up around the cursor.
Matte 3D spheres hanging in soft studio light, each floating on its own rhythm, with far ones out of focus and the whole scene parallaxing with the cursor.
Soft focus
Customize
Usage
import { SoftSpheres } from "@/components/motionkit/soft-spheres";
<SoftSpheres
className="h-[32rem] rounded-3xl"
>
<h1>Your hero</h1>
</SoftSpheres>Motion
The exact curves this component runs, plotted with Motion's own maths.
Spheres float
Runs on its own
Friendly SaaS and fintech heroes, design tools and agencies, onboarding screens and playful but modern brands.
Each sphere is a circle filled with a radial gradient whose centre sits up and to the left: near white there, your colour through the middle, then darker towards the far edge, which is what makes a flat circle read as a matte ball. A second, faint gradient adds bounced light on the lower rim, and a blurred ellipse beneath gives it a shadow. Spheres are sorted by depth, the far ones are blurred like a shallow depth of field, each bobs on its own sine, and the pointer offsets them by depth for parallax.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/soft-spheres.jsonnpm install motionSave as components/motionkit/soft-spheres.tsx.
"use client";
import { useEffect, useRef, type ReactNode } from "react";
type SoftSpheresProps = {
children?: ReactNode;
/** Sphere colours; each sphere picks one. */
colors?: string[];
/** Background behind the spheres. */
background?: string;
/** Number of spheres. */
count?: number;
/** How far they float, 0 for still. */
float?: number;
/** Let the spheres shift with the pointer, nearer ones more, for depth. */
interactive?: boolean;
className?: string;
};
type Sphere = { x: number; y: number; z: number; r: number; color: string; phase: number; rate: number };
// canvas colours must be plain values, so lighter and darker shades are mixed here
const rgb = (hex: string) => {
const value = parseInt(hex.replace("#", "").padEnd(6, "0").slice(0, 6), 16);
return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
};
const shade = (hex: string, toward: number, amount: number, alpha = 1) => {
const [r, g, b] = rgb(hex).map((channel) => Math.round(channel + (toward - channel) * amount));
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
};
/**
* Matte 3D spheres hanging in soft light, like a studio render. Each is lit from the upper left with a gentle
* rim of bounced light, floats on its own slow rhythm, and drifts with the pointer by its depth, so the scene parallaxes.
*/
export function SoftSpheres({
children,
colors = ["#FF9EBB", "#8FB4FF", "#C7A9FF", "#FFD59A", "#8FE6D1"],
background = "#0F1016",
count = 9,
float = 1,
interactive = true,
className = "",
}: SoftSpheresProps) {
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const canvas = canvasRef.current;
const area = canvas?.parentElement;
const context = canvas?.getContext("2d");
if (!canvas || !area || !context) return;
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let width = 0;
let height = 0;
let ratio = 1;
let frame = 0;
let visible = true;
let last = 0;
let time = 0;
const pointer = { x: 0, y: 0, tx: 0, ty: 0 };
let spheres: Sphere[] = [];
let seed = 3;
const random = () => ((seed = (seed * 16807) % 2147483647) - 1) / 2147483646;
function layout() {
seed = 3;
const unit = Math.min(width, height);
spheres = Array.from({ length: count }, (_, index) => {
const z = random();
return {
x: (0.08 + random() * 0.84) * width,
y: (0.1 + random() * 0.8) * height,
z,
r: unit * (0.04 + z * 0.12) * (index === 0 ? 1.6 : 1),
color: colors[index % colors.length],
phase: random() * Math.PI * 2,
rate: 0.3 + random() * 0.4,
};
}).sort((a, b) => a.z - b.z);
}
function resize() {
const rect = canvas!.getBoundingClientRect();
ratio = Math.min(window.devicePixelRatio || 1, 2);
width = rect.width;
height = rect.height;
canvas!.width = Math.max(1, Math.round(width * ratio));
canvas!.height = Math.max(1, Math.round(height * ratio));
layout();
}
function drawSphere(sphere: Sphere) {
const c = context!;
const bob = still ? 0 : Math.sin(time * sphere.rate + sphere.phase) * sphere.r * 0.25 * float;
const depth = 0.3 + sphere.z;
const x = sphere.x + pointer.x * 40 * depth;
const y = sphere.y + bob + pointer.y * 30 * depth;
const r = sphere.r;
// far spheres are softly out of focus
c.filter = sphere.z < 0.3 ? `blur(${((0.3 - sphere.z) * 14).toFixed(1)}px)` : "none";
// a soft shadow it casts below and to the right
c.fillStyle = "rgba(0, 0, 0, 0.35)";
c.beginPath();
c.ellipse(x + r * 0.25, y + r * 1.15, r * 0.8, r * 0.18, 0, 0, Math.PI * 2);
c.save();
c.filter = `blur(${Math.max(4, r * 0.25).toFixed(1)}px)`;
c.fill();
c.restore();
// the body: lit from the upper left, falling into shade at the far edge
const body = c.createRadialGradient(x - r * 0.38, y - r * 0.42, r * 0.05, x - r * 0.1, y - r * 0.1, r * 1.12);
body.addColorStop(0, shade(sphere.color, 255, 0.6));
body.addColorStop(0.35, sphere.color);
body.addColorStop(0.8, shade(sphere.color, 0, 0.35));
body.addColorStop(1, shade(sphere.color, 0, 0.6));
c.fillStyle = body;
c.beginPath();
c.arc(x, y, r, 0, Math.PI * 2);
c.fill();
// bounced light along the lower right rim
const rim = c.createRadialGradient(x + r * 0.55, y + r * 0.6, r * 0.1, x + r * 0.4, y + r * 0.45, r * 0.9);
rim.addColorStop(0, shade(sphere.color, 255, 0.35, 0.45));
rim.addColorStop(1, shade(sphere.color, 255, 0.35, 0));
c.fillStyle = rim;
c.beginPath();
c.arc(x, y, r, 0, Math.PI * 2);
c.fill();
c.filter = "none";
}
function draw() {
const c = context!;
c.setTransform(ratio, 0, 0, ratio, 0, 0);
c.clearRect(0, 0, width, height);
for (const sphere of spheres) drawSphere(sphere);
}
function loop(now: number) {
const dt = last ? Math.min(0.05, (now - last) / 1000) : 0;
last = now;
time += dt;
pointer.x += (pointer.tx - pointer.x) * 0.05;
pointer.y += (pointer.ty - pointer.y) * 0.05;
draw();
frame = visible ? requestAnimationFrame(loop) : 0;
if (!frame) last = 0;
}
resize();
draw();
if (!still) frame = requestAnimationFrame(loop);
const resizeObserver = new ResizeObserver(() => {
resize();
draw();
});
resizeObserver.observe(canvas);
const visibilityObserver = new IntersectionObserver(([entry]) => {
visible = entry.isIntersecting;
if (visible && !frame && !still) frame = requestAnimationFrame(loop);
});
visibilityObserver.observe(canvas);
function move(event: PointerEvent) {
if (!interactive || still || event.pointerType === "touch") return;
const rect = canvas!.getBoundingClientRect();
pointer.tx = ((event.clientX - rect.left) / rect.width - 0.5) * 2;
pointer.ty = ((event.clientY - rect.top) / rect.height - 0.5) * 2;
}
const leave = () => {
pointer.tx = 0;
pointer.ty = 0;
};
area.addEventListener("pointermove", move);
area.addEventListener("pointerleave", leave);
return () => {
cancelAnimationFrame(frame);
resizeObserver.disconnect();
visibilityObserver.disconnect();
area.removeEventListener("pointermove", move);
area.removeEventListener("pointerleave", leave);
};
// the colours are compared by value, so a new array with the same colours doesn't restart it
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [colors.join(), count, float, interactive]);
return (
<div className={`relative isolate overflow-hidden ${className}`} style={{ background: `radial-gradient(ellipse at 30% 20%, ${shade(background, 255, 0.06)}, ${background} 70%)` }}>
<canvas ref={canvasRef} aria-hidden className="pointer-events-none absolute inset-0 -z-10 size-full" />
{children}
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| colors | string[] | pink, blue, lilac, peach, mint | Sphere colours; each sphere picks one. |
| background | string | "#0F1016" | Colour behind the spheres. |
| count | number | 9 | Number of spheres. |
| float | number | 1 | How far they float. 0 for still. |
| interactive | boolean | true | Parallax with the pointer by depth. |
| children | ReactNode | — | Your content, layered above. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Nothing beyond React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/soft-spheres.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the spheres are drawn once and stay put. It also stops animating off screen.
A sea of dots on a 3D plane rolling in slow waves to the horizon, swelling up around the cursor.
Thousands of fine dots forming a slowly turning 3D sphere with a ripple across its surface, drifting aside from the cursor.
A retro perspective grid rolling toward a glowing horizon, synthwave style.