Bubble Rise
Translucent 10 to 50 px bubbles appear below the frame's edge every 500 ms, at a random position, size and speed, then rise with a sway over 3 to 7 s and fade out before the top — a continuous, never-repeating stream in CSS and 2.4 KB of JavaScript, no canvas, paused off-screen, still when the user reduces motion.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Liquid has 31 effects, including 6 free. Explore the category →
3 usage examples



How it works
The HTML holds only an empty container, .bubble-container, inside the root .fx-0395-root: 300 px tall, overflow: hidden, with a navy gradient #1a1a2e → #0a0a1a. Each bubble is a div.bubble created by the script: round, placed 100 px below the bottom edge, painted with an off-center radial gradient (white at 40% in the top left, indigo at 20%, then transparent) and ringed by a white border at 20%. That off-center highlight is what gives it volume. The linear bubbleRise animation lifts the bubble 150 px while pushing it 20 px to the right and swelling it to ×1.1, then another 150 px while bringing it 10 px back left, shrunk to ×0.8 and fading from 0.8 to 0 opacity: the bubble sways and disappears before reaching the top.
The script draws four values per bubble: a diameter of 10 to 50 px, a position from 0 to 100% of the width, a rise time of 3 to 7 s, and a start delay of 0 to 2 s. One bubble is created every 500 ms and removed from the page as soon as its rise ends, which keeps about a dozen bubbles on screen (measured: 7 to 13 depending on the moment). At startup, ten bubbles launch with a negative delay: they are already on their way, at different heights, so the frame is never empty. Each .bubble-container on the page gets its own stream: several bubble blocks coexist without any code change.
The stream only runs while someone is looking. One IntersectionObserver per container and the visibilitychange event stop bubble creation when the block leaves the screen or the tab is hidden; bubbles in flight finish their rise and disappear. Measured in Chromium 151, Firefox 153 and WebKit 26: block scrolled off-screen for 9 s, 0 bubbles created and 0 left; back on screen, a new wave of ten bubbles already on their way, 9 to 13 bubbles visible 1.5 s later. The script is wrapped in a function and adds no global names.
Accessibility
- Reduced motion: when
prefers-reduced-motion: reducematches, the script starts no stream and places twelve still bubbles spread between 5 and 85% of the height, at 70% opacity; the CSS removes the animation from.fx-0395-root .bubble. You see sparkling water, nothing rises. Measured: 0% of pixels change over 500 ms in all three engines. - Decorative content: the bubbles are empty
divelements with no text and no role, skipped by screen readers. Any text you place on top (heading, button) stays in the page's normal flow: keep it outside the container or above it withz-index. - Legibility: the bubbles are very transparent (40% highlight, 20% border) and pass behind text without hiding it. On a light background they become almost invisible: strengthen the border rather than darkening the text.
- Resources: creation stops off-screen and in hidden tabs, and no bubbles pile up (each one is removed when its rise ends).
Browser compatibility
CSS (transform and opacity animations, radial gradient) + 2.4 KB of dependency-free JavaScript: setInterval, IntersectionObserver, matchMedia. Measured in Chromium 151, Firefox 153 and WebKit 26: same stream, same off-screen pause, same still bubbles under reduced motion, no errors.
Without IntersectionObserver, the block is treated as always visible: the stream runs continuously, but stops when the tab is hidden. Without JavaScript, the container stays an empty navy background.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0395-root">
<div class="bubble-container" style="width:100%;min-height:300px;">
<!-- div.bubble elements added by the script -->
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Rate (JS — setInterval(…, 500)) |
one bubble every 500 ms | 250 doubles the number of bubbles (about twenty on screen), 1000 gives a sparse trickle. The visible count is roughly the average rise time divided by the interval. |
Size (JS — 10 + 40 * Math.random()) |
10 to 50 px | 5 + 9 * Math.random() for fine sparkling-water bubbles, 30 + 50 * Math.random() for big soap bubbles. Below 10 px, strengthen the border so they stay visible. |
Rise time (JS — 3 + 4 * Math.random()) |
3 to 7 s | Longer durations slow the bubbles; very close durations (4 + 1 * Math.random()) give a steady, less natural stream. |
Rise height (CSS — -150px and -300px in bubbleRise) |
300 px, fading before the top | For a 500 px container, use −240 and −480 px. The start (bottom: -100px on .bubble) can move up to −50 px so bubbles show up sooner. |
Bubble look (CSS — background and border of .fx-0395-root .bubble) |
40% white highlight, 20% indigo tint, 20% white border | On light water, use a 60 to 85% border and a solid white highlight. For iridescent soap bubbles, replace the indigo with a pink-to-green gradient. |
Water color (CSS — background of .bubble-container) |
#1a1a2e → #0a0a1a | A medium blue (#2f8dbd) brings out the highlights; background: none sets the bubbles on your own background. |
Reduced motion (JS — i < 12 in the reduce branch) |
12 still bubbles | Number of still bubbles shown when the user reduces motion. Keep enough for the frame to read as sparkling water. |
FAQ
IntersectionObserver per container and the visibilitychange event stop the timer when the block leaves the screen or the tab goes to the background. Bubbles already launched finish their rise and are removed. Measured in all three engines: 9 s off-screen, no bubbles created, none left; on return, ten bubbles start at once, already on their way.bubbleRise (−150 and −300 px) by the same ratio..fx-0395-root .bubble-container and gives each one its own stream and observer; it uses no id. The .bubble rule is scoped to the effect's root, so it does not touch a bubble class already in your site (chat bubbles, for example).