Liquid Button
A pill button that fills with liquid on hover or keyboard focus: a second gradient rises from the bottom in 0.5 s, topped by an SVG wave that scrolls endlessly, then drains when the pointer leaves — pure CSS, 2.2 KB, no JavaScript, a simple color fade 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 <button class="liquid-btn"> (20 × 50 px padding, bold 1.2rem text, 50 px corners, overflow: hidden) stacks three layers. At the back, .liquid-bg: an indigo to violet gradient (#6366f1 → #8b5cf6) at z-index: -2. Above it, .liquid-fill: pinned to the bottom, full width, a cyan to blue gradient (#06b6d4 → #3b82f6), height 0. Last, the label at z-index: 1. The button has z-index: 0 and position: relative: it creates its own stacking context, so the negative layers stay behind the label but in front of the page. Both layers are <span>s, the only kind of content a button accepts.
The fill fits in one rule: .liquid-btn:hover .liquid-fill, .liquid-btn:focus-visible .liquid-fill { height: 100% }, animated by transition: height .5s cubic-bezier(.4, 0, .2, 1) — a brisk start and a soft finish, like a level settling. The liquid surface is the ::before pseudo-element of .liquid-fill: a 30 px band straddling its top edge (top: -15px), painted with an SVG data URI — two ripples on a 600 × 30 px tile repeated across — and shifted from 0 to −600 px in 2 s, in a linear loop. The tile joins up with itself: the wave scrolls at 300 px per second with no visible jump.
Two settings keep the wave whole. The SVG declares preserveAspectRatio='none': without it, its drawing (1200 × 120) would be shrunk to fit the 600 × 30 px tile and cover only half of it, and the wave would show up in chunks with straight edges. The band is calc(100% + 600px) wide: it always overhangs by one full tile on the right, so its edge stays outside the button throughout the shift, whatever the button's width (measured in Chromium 151, Firefox 153 and WebKit 26: the wave's right edge passes the button's at every moment of the cycle, by 10 to 597 px). At rest, the upper half of that band shows at the bottom of the button: a thin line of liquid ripples there, and the button looks "almost empty" rather than switched off.
Accessibility
- Keyboard: the fill also responds to
:focus-visible. Measured: one press of Tab fills the button to the top in Chromium and Firefox. The browser's focus ring stays visible,overflow: hiddendoes not clip it. On a Mac, Safari only moves Tab focus to buttons when "Press Tab to highlight each item" is on (otherwise Option + Tab). - Reduced motion: under
prefers-reduced-motion: reduce, the liquid no longer rises. The fill takes the full height from the start, invisible, and fades in over 0.3 s on hover or focus; the wave stops scrolling. Measured in all three engines: 0% of pixels changing at rest, solid color on hover. - Contrast: white label on the resting gradient, 4.5:1 on the indigo
#6366f1and 4.2:1 on the violet#8b5cf6; on the liquid, 2.4:1 on the cyan#06b6d4and 3.7:1 on the blue. The 19 px bold label meets the large-text threshold (3:1) everywhere except on the cyan: darken the top of the fill gradient (#0891b2, 3.7:1) if the label is long or thin. - Touch: with a finger, mobile browsers apply
:hoverto the touched element: the button fills as it is tapped and may stay full until the next tap elsewhere. No information depends on the fill, the label is enough.
Browser compatibility
Pure CSS (a height transition, a pseudo-element, an SVG data URI image, :focus-visible), 2.2 KB, no dependency. Measured in Chromium 151, Firefox 153 and WebKit 26: same 0.5 s fill, same continuous wave, same fade under reduced motion. :focus-visible exists since Chrome 86, Firefox 85 and Safari 15.4; before that, the keyboard fill is missing and hover still works.
Browser without :focus-visible: hover still fills the button, keyboard focus only shows the ring. Without SVG data URIs (a theoretical case), the liquid rises with no wave. The button stays a real button element: it can be clicked, tabbed to and announced everywhere.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0393-root">
<div class="liquid-btn-container">
<button class="liquid-btn">
<span class="liquid-bg"></span>
<span class="liquid-fill"></span>
<span>Hover Me</span>
</button>
</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 |
|---|---|---|
Empty button color (CSS — .liquid-bg) |
linear-gradient(135deg, #6366f1, #8b5cf6) |
A dark, muted background (steel blue, wine) makes the rising liquid stand out better than an already bright one. |
Liquid color (CSS — .liquid-fill and the SVG fill) |
#06b6d4 → #3b82f6, wave %2306b6d4 |
Change both together: the wave should take the color of the top of the gradient, or a band of the old color floats on the liquid. In the SVG, # is written %23. |
Fill speed (CSS — transition: height .5s) |
0.5 s, cubic-bezier(.4, 0, .2, 1) curve |
0.8 s gives a slow, "tank-like" fill; 0.3 s a snappy button. The same duration applies to draining. |
Wave speed (CSS — animation: 2s … liquidWave) |
2 s for 600 px, i.e. 300 px per second | 4 s calms the surface (150 px/s), 1 s makes it choppy. Keep −600 px in @keyframes liquidWave: it is the tile width, which makes the loop seamless. |
Wave height (CSS — height: 30px, top: -15px, tile size 600px 30px) |
30 px, centered on the liquid's edge | 40 px (with top: -20px and a 600px 40px tile) deepens the waves. Keep top at half the height so the wave stays astride the level. |
Level on hover (CSS — height: 100%) |
full | height: 70% leaves room at the top: the wave stays visible for the whole hover instead of passing above the button. |
FAQ
overflow: hidden clips it, leaving only a cyan rim. That is intended (the button is "full to the brim"). To keep the wave visible, stop the level at 70 or 80% instead of 100%.:hover rule and drive the height from your script, for instance fill.style.height = percent + '%' at each step. The 0.5 s transition smooths the jumps between values and the wave keeps scrolling on the surface. Then announce progress as text (role="progressbar" with aria-valuenow); the level alone cannot be read by a screen reader.