Button
A button made of glass. Clear glass bends the page behind it; tinted glass takes your background colour.
Latest change Improved v3.0.9 Under reduced motion a change fades over 150 ms instead of jumping, and a loading spinner breathes instead of standing still.
- v3.0.9 Improved Under reduced motion a change fades over 150 ms instead of jumping, and a loading spinner breathes instead of standing still.
- v3.0.4 Improved A label or an icon that changes inside a glass button now changes as it does in Action Button: plain text comes in letter by letter, each letter out of a blur and the dark, and an icon rises in as one piece out of a soft blur. Button and Button Group do it by themselves (Save → Saved needs nothing from you); nothing plays for what was there from the start, or under reduced motion. It is
GlassSwapofglass-layer.tsx, exported for a changing label of your own inside glass. - v2.3.3 Improved For a spring of your own on a host's size: GlassLayer's
slackalso takes{ x, y }, room one way alone for glass that only travels that way, and the engine hasdrive(step), which steps your spring at the start of each frame, so the glass is drawn as its host is on that same frame. - v2.3.1 Improved GlassLayer takes
slackandexcept.slack(px) is for glass you move or resize over a still page: its picture of the page is taken that much wider, and the glass reads from it for as long as it stays inside.exceptis a CSS selector of elements left out of what the glass bends, for glass that moves alongside it. - v2.3.0 Improved The example on the Button page shows
tintin five steps, 0, 0.25, 0.5, 0.75 and 1, each over a flat disc of its own. It showed only the two ends. - v2.3.0 Fixed The
tintof clear glass covers it to its edge when the glass lies on a picture. Over a photo or a coloured block, the rim took what was under the glass for a neighbour and mirrored it over the tint, so only the middle looked tinted. The rim now mirrors what differs from what the glass lies on: a neighbour beside it shows as before, and glass on a plain page has not changed. - All changes→
Use it for
- One action: a call to action, a toolbar button, a link that looks like a button.
- Clear glass over imagery or colour, where the bend shows.
Not for
- An async action whose result should show on the button: use GlassActionButton.
- Choosing between options: use GlassTabs.
- Every button of a dense form: keep the glass for the action that matters.
Installation
npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/button.jsonThe button underneath is UI SDK's, so Button needs @ui-sdk/core and @ui-sdk/react. Return a Promise from onClick and the button stays pending until it settles: it ignores further presses and says so to screen readers. The install command adds both packages at the exact version this was built on: UI SDK is in beta and its API may still change.
Usage
import { GlassButton } from '@/components/liquid-glass'
<GlassButton>Get started</GlassButton>
<GlassButton material="tinted" className="bg-sky-500 text-white">Save</GlassButton>
<GlassButton asChild>
<Link href="/docs">Read the docs</Link>
</GlassButton>Examples
material tint size icon pull One row per prop, its values next to each other: material (clear glass and three colours of tinted glass), tint in five steps from 0 to 1 over flat colour, the four of size, icon with iconPosition, and pull. The buttons of a row sit 10 px apart: hold one and pull it towards its neighbour, and the two melt into one body.
API reference
| Prop | Type | Default |
|---|---|---|
tempo On | 'default' | 'quick' | 'default' |
material Clear bends the page; tinted uses the background colour. | 'clear' | 'tinted' | 'clear' |
size Height 32, 40, 48 or 64 px. | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
icon An icon element (e.g. a Hugeicons icon). | ReactNode | — |
iconPosition Which side the icon sits on. | 'start' | 'end' | 'end' |
tint Clear glass only: how much tint covers the backdrop (0–1). | number | 0.6 |
asChild Put the glass on the single child element instead of a | boolean | false |
pull Hold and drag: the button follows the pointer a little way, stretches along the pull and swings back when let go. | boolean | true |
…rest Passed to the button: | button attributes | — |
Accessibility
- A real
<button>(or your own element withasChild): focus, Enter and Space work as usual. - The glass canvas is
aria-hidden; only your label is announced. - Icon-only buttons need an
aria-label.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.