A wall of frosted glass tiles over slowly drifting colour: soft, bright light inside each pane, sharp colour in the gaps, and a glint where the pointer is.
Glass bubbles rising slowly through soft light, each with a bright highlight, a rim that catches colour, and a gentle sway on the way up.
Customize
Usage
import { GlassBubbles } from "@/components/motionkit/glass-bubbles";
<GlassBubbles
className="h-[32rem]"
>
<h1>Your hero</h1>
</GlassBubbles>Motion
The exact curves this component runs, plotted with Motion's own maths.
Bubbles rise
Runs on its own
Sway
Runs on its own
Wellness, beauty and drinks brands, calm product heroes, waiting and success screens, and anywhere that wants gentle, airy movement.
Each bubble is a round span painted with three radial gradients: a bright highlight near the top left, a soft reflection near the bottom right, and a ring of colour and light at the rim, which is what makes it read as glass rather than a dot. An outer span rises the bubble from below the frame to above it with a CSS keyframe measured in container units, and an inner span sways it side to side on its own rhythm. Sizes, speeds and positions come from a fixed scatter, so the server and the browser agree, and bigger bubbles rise a little faster, as they do in water.
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/glass-bubbles.jsonnpm install motionSave as components/motionkit/glass-bubbles.tsx.
"use client";
import type { CSSProperties, ReactNode } from "react";
type GlassBubblesProps = {
children?: ReactNode;
/** How many bubbles are rising at once. */
count?: number;
/** Colours caught in the bubbles' rims and the glow behind them. */
colors?: [string, string];
background?: string;
/** Seconds for an average bubble to rise the full height. */
duration?: number;
/** Largest bubble diameter, in pixels. */
size?: number;
className?: string;
};
// a fixed scatter, so the bubbles sit the same way on the server and in the browser
const scatter = (seed: number) => {
const x = Math.imul(seed + 1, 2654435761) >>> 0;
return (x % 10_000) / 10_000;
};
/**
* Glass bubbles rising slowly through soft light, each with a bright highlight, a coloured rim where it catches the
* light, and a gentle sway on the way up. Pure CSS: gradients and transforms only, so it's light enough to sit
* behind any hero.
*/
export function GlassBubbles({
children,
count = 16,
colors = ["#B9C7FF", "#5FAEB4"],
background = "#0C1010",
duration = 16,
size = 120,
className = "",
}: GlassBubblesProps) {
const [a, b] = colors;
const bubbles = Array.from({ length: count }, (_, i) => {
const d = Math.round(size * (0.25 + scatter(i * 3) * 0.75));
return {
d,
left: scatter(i * 3 + 1) * 100,
// bigger bubbles rise a little faster, as they do in water
rise: duration * (1.25 - (d / size) * 0.45) * (0.85 + scatter(i * 7) * 0.3),
delay: -scatter(i * 5 + 2) * duration * 1.5,
sway: 10 + scatter(i * 11) * 26,
tint: i % 2 ? a : b,
};
});
return (
<div data-bubbles="" className={`relative isolate overflow-hidden ${className}`} style={{ backgroundColor: background }}>
<style>{`
@keyframes bubbles-rise{from{transform:translateY(0)}to{transform:translateY(calc(-100cqh - 140%))}}
@keyframes bubbles-sway{from{transform:translateX(calc(var(--sway) * -1))}to{transform:translateX(var(--sway))}}
[data-bubbles]{container-type:size}
@media (prefers-reduced-motion:reduce){[data-bubbles] [data-rise],[data-bubbles] [data-sway]{animation:none!important}[data-bubbles] [data-rise]{transform:translateY(calc(var(--rest) * -1cqh))}}
`}</style>
<div aria-hidden className="absolute inset-0 -z-20" style={{ background: `radial-gradient(60% 50% at 30% 100%, color-mix(in srgb, ${b} 22%, transparent), transparent 70%), radial-gradient(50% 45% at 80% 20%, color-mix(in srgb, ${a} 16%, transparent), transparent 70%)` }} />
{bubbles.map((bubble, i) => (
<span
key={i}
aria-hidden
data-rise=""
className="absolute -z-10"
style={
{
left: `${bubble.left}%`,
top: "100%",
width: bubble.d,
height: bubble.d,
marginLeft: -bubble.d / 2,
"--rest": (scatter(i * 13) * 90 + 15).toFixed(0),
animation: `bubbles-rise ${bubble.rise.toFixed(2)}s linear ${bubble.delay.toFixed(2)}s infinite`,
} as CSSProperties
}
>
<span
data-sway=""
className="block size-full rounded-full"
style={
{
"--sway": `${bubble.sway.toFixed(0)}px`,
animation: `bubbles-sway ${(3 + scatter(i * 17) * 3).toFixed(2)}s ease-in-out ${(-scatter(i * 19) * 4).toFixed(2)}s infinite alternate`,
// a bright spot up top, a soft reflection below, and the rim catching colour
background: `radial-gradient(circle at 32% 26%, rgb(255 255 255 / 0.75), rgb(255 255 255 / 0.12) 16%, transparent 36%), radial-gradient(circle at 68% 78%, rgb(255 255 255 / 0.16), transparent 34%), radial-gradient(circle at 50% 50%, transparent 58%, color-mix(in srgb, ${bubble.tint} 30%, transparent) 76%, rgb(255 255 255 / 0.28) 96%, transparent 100%)`,
boxShadow: `inset 0 0 0 1px rgb(255 255 255 / 0.14), 0 0 ${Math.round(bubble.d / 4)}px color-mix(in srgb, ${bubble.tint} 18%, transparent)`,
} as CSSProperties
}
/>
</span>
))}
{children}
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Your content, above the bubbles. |
| count | number | 16 | How many bubbles rise at once. |
| colors | [string, string] | periwinkle, teal | Colours in the rims and the glow behind. |
| background | string | "#0C1010" | Colour underneath. |
| duration | number | 16 | Seconds for an average bubble to rise the full height. |
| size | number | 120 | Largest bubble diameter, in px. |
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/glass-bubbles.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the bubbles rest where they are instead of rising.
A wall of frosted glass tiles over slowly drifting colour: soft, bright light inside each pane, sharp colour in the gaps, and a glint where the pointer is.
Drifting, blurred color fields for hero sections and empty states.
A soft ribbon of light behind the pointer, across the window or inside one section.
Breathe easy