Skip to documentation content

Metaballs

Drift soft blobs that merge and separate like liquid, with an optional ball that follows the pointer.

metaballs-demo

Overview

Metaballs draws a handful of round blobs that wander slowly and melt into one another when they meet, then pull apart again. Each ball takes a color from colors in turn, and where two merge their colors blend over a short distance instead of averaging into mud. With followPointer, one more ball tracks the pointer and merges with the rest, which makes an empty state, a sign-in panel, or a loading screen feel responsive without demanding attention.

Use a small count and low spread for a compact cluster behind a logo, or more balls across the full container for a background. Set softness above 0 for a blurred glow instead of crisp edges, and backgroundColor="transparent" to place the blobs over your own surface.

Installation

npm install honestui

Usage

import { Metaballs } from "honestui/shaders"

<div className="h-80 bg-neutral-950">
  <Metaballs
    className="size-full"
    colors={["#6366f1", "#ec4899"]}
    count={8}
  />
</div>

Accessibility

Metaballs is decorative: the canvas is hidden from assistive technology, and text or actions belong in normal HTML above it. The pointer ball is an enhancement only, so nothing should depend on it, and it does nothing for keyboard or touch users. Animation pauses while the effect is offscreen, while the document is hidden, and when the user prefers reduced motion; a still frame is rendered, and the pointer ball still follows the pointer without easing. Use paused for your own control, and give the container a background for when WebGL is unavailable.

API Reference

PropTypeDefaultDescription
countnumber9Number of drifting balls, from 1 to 20.
colorsstring[]["#6366f1", "#a855f7", "#ec4899", "#38bdf8"]Ball colors, up to 8. Balls take them in turn; the pointer ball uses the first.
sizenumber1Overall ball size.
spreadnumber0.8How far the balls wander, from 0 (clustered in the center) to 1 (the full container).
softnessnumber0Softness of the edges, from 0 (crisp) to 1 (a soft glow).
speednumber1Animation speed. Changing it never makes the balls jump.
followPointerbooleantrueAdds a ball that follows the pointer and merges with the others.
backgroundColorstring"transparent"Background color, or "transparent" to let the container show through.
seednumber1Changes the ball paths while keeping the same look.
pausedbooleanfalseRenders a static frame instead of animating.
classNamestring–Class for sizing and positioning the container.