Solid to Glass Button
A solid button that turns to glass on hover or keyboard focus: its colour fades, the blur rises to 16 px and its edges ripple for 0.6 s via an SVG filter.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Glassmorphism has 47 effects, including 6 free. Explore the category →
3 usage examples



How it works
At rest it is an opaque button: 85% indigo, 14 px corners, 153 × 46 px with its original label. It sits on .lg-morph-btn-bg, a halo that sticks out 20 px all round and whose gradient — indigo, violet, fuchsia, pink — goes back and forth in 4 seconds. As long as nothing is touched, that halo is just a coloured frame: the button hides it.
When the pointer enters, the script adds the lg-morph-btn--glass class. In half a second the fill drops to 10% white, backdrop-filter rises from 0 to blur(16px) saturate(1.8) and a slanted sheen appears: the button changes material and shows, frosted, what it was covering. The transition curve overshoots slightly before settling — the blur reaches 16.5 px before coming back to 16. Its size does not move.
At the same moment the script applies the SVG filter shipped inside the root: feTurbulence noise pushes the button's pixels through feDisplacementMap, whose strength rises from 0 to 12 then falls back within 0.6 s. The edges buckle like a drop that has just been touched, then the filter is removed. When the pointer leaves, the class goes and the button is solid again. Each copy of the effect gets its own filter id: two buttons on a page never ripple for one another.
Accessibility
- Keyboard: focus arriving by Tab produces the same turn to glass, ripple included, plus a 2 px white outline; the button turns solid again when it loses focus. Measured in Chromium and Firefox, and in WebKit with Option + Tab (Safari's default setting). A mouse click does not replay the ripple.
- Reduced motion: the script reads
prefers-reduced-motionon every hover. When it is on, the SVG filter is not applied — measured:filter: nonethroughout the hover — and the halo stops sliding. The change of material stays, since that is what signals the state. - Touch: there is no hover on a touch screen. Measured in Chromium and WebKit touch emulation: a tap triggers the turn to glass, and the button stays glass until you tap elsewhere. If the button changes page you hardly see it; otherwise, plan for it.
- Contrast: white label at 4.4:1 on the solid button — just under the 4.5:1 threshold — and between 2.3:1 and 3.7:1 once in glass, when the halo's fuchsia passes behind. The text shadow helps a little; for a truly readable label, darken the glass:
.lg-morph-btn--glass { background: rgba(30, 27, 75, .35) }. - Screen readers: nothing is announced when the material changes, on purpose — the state is decorative and the label does not change. The filter's
<svg>carriesaria-hidden="true".
Browser compatibility
Measured under Playwright in Chromium, Firefox and WebKit: class added and removed, ripple visible in the captures of all three engines, two independent copies, no name added to window. The frosting itself could only be looked at in Chromium: automated captures of Firefox and WebKit do not paint backdrop-filter, even on a minimal test block. Real Safari: not verified. Minimum versions per MDN: inset for the halo (Chrome 87, Edge 87, Safari 14.1), backdrop-filter (Firefox 103; -webkit- prefix declared for Safari before 18). SVG filters and beginElement() have existed far longer in those four browsers.
Without JavaScript the button stays solid and fully usable: only the effect goes. Without the <svg> block the script finds no filter and settles for the change of material, with no error. Without backdrop-filter the glass state is a plain 10% white veil: over a busy background, give it a denser tint.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0323-root">
<div class="lg-morph-btn-wrap">
<div class="lg-morph-btn-bg"></div>
<button type="button" class="lg-morph-btn" data-morph-btn>…</button>
<svg class="lg-morph-defs" width="0" height="0" aria-hidden="true" focusable="false">
<filter id="lgMorphDisplace">
<feTurbulence type="fractalNoise"></feTurbulence>
<feDisplacementMap>
<animate attributeName="scale"></animate>
</feDisplacementMap>
</filter>
</svg>
</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 |
|---|---|---|
Solid colour (CSS — .lg-morph-btn { background }) |
rgba(99, 102, 241, .85), 20% white border |
Use your brand colour. Leave a little transparency (0.85 to 0.95): the fade to glass is softer than from a 100% flat fill. |
Glass state (CSS — .lg-morph-btn.lg-morph-btn--glass) |
10% white, blur(16px) saturate(1.8), 30% border |
Over a detailed photo, raise the blur to 24 px. A dark tint (rgba(30,27,75,.35)) keeps the label readable. Edit both filter lines, prefixed and unprefixed. |
Length and bounce of the change (CSS — transition: .5s cubic-bezier(.34, 1.56, .64, 1)) |
0.5 s, with overshoot | The curve's second figure (1.56) makes the overshoot; bring it down to 1 for a fade with no bounce. Under 0.3 s the change of material feels abrupt. |
Ripple strength (HTML — <animate values="0;12;0" dur="0.6s">) |
strength 12, 0.6 s | 20 gives a frankly liquid button, 6 a shiver. If you change the duration, also change the script's 600 delay, which removes the filter at the end. |
Ripple grain (HTML — <feTurbulence baseFrequency="0.012 0.035">) |
wide waves, a single octave | Smaller values give one big wave; past 0.05 the edges bristle and the label gets hard to read during the effect. |
Halo (CSS — .lg-morph-btn-bg) |
20 px overhang, four colours, 4 s loop | Change the gradient colours, or delete the element to set the button over your own image: the glass then frosts whatever lies behind it on the page. |
Size (CSS — padding: 14px 32px, font-size: .9rem, border-radius: 14px) |
153 × 46 px with the original label | The button does not change size when it turns to glass: you can give it a fixed width or place it in a grid without anything shifting around it. |
FAQ
.fx-0323-root, renames its filter (lgMorphDisplace-0, -1…) and wires every [data-morph-btn] button it contains: several buttons can therefore share one root and one <svg> block, like the four quiz answers. Two limits: the script must come after the HTML, and only the roots present at that moment are wired: for a root added later, run the script again, it skips the ones already set up; a button slipped afterwards into a root that is already wired stays inert..lg-morph-btn.is-chosen next to .lg-morph-btn--glass — rather than reusing the one the script wipes. Remember aria-pressed so the state is announced too.