# Glass Bubbles

> 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.

Category: Backgrounds · Free · Updated 2026-11-11 · Live demo: https://www.motionkitui.com/components/glass-bubbles

## When to use it

Wellness, beauty and drinks brands, calm product heroes, waiting and success screens, and anywhere that wants gentle, airy movement.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/glass-bubbles.json
```

Or copy `components/motionkit/glass-bubbles.tsx` below. Requires react and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Not applicable.** A decorative background.
- **Screen readers: Pass.** Every bubble is hidden; only your content is read.
- **Reduced motion: Pass.** With reduced motion on, the bubbles rest where they are instead of rising.
- **Colour contrast: Partial.** Ivory text measures 14:1 against the background and 5.5:1 over most of a bubble, but drops under 2:1 for a moment when a bubble's bright highlight drifts behind it. Fine for headings; keep long reading text off it.

## Source

```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>
  );
}
```
