Skip to content

Components

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.
  1. 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.
  2. 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 GlassSwap of glass-layer.tsx, exported for a changing label of your own inside glass.
  3. v2.3.3 Improved For a spring of your own on a host's size: GlassLayer's slack also takes { x, y }, room one way alone for glass that only travels that way, and the engine has drive(step), which steps your spring at the start of each frame, so the glass is drawn as its host is on that same frame.
  4. v2.3.1 Improved GlassLayer takes slack and except. 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. except is a CSS selector of elements left out of what the glass bends, for glass that moves alongside it.
  5. v2.3.0 Improved The example on the Button page shows tint in 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.
  6. v2.3.0 Fixed The tint of 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.
  7. All changes→
glass-button-clear.svelte

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

The 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

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

Every prop, side by side
glass-button-props.svelte
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

PropTypeDefault
tempo

On GlassButton: quick: the label changes in 250 ms instead of about 400 (Emil Kowalski's timings). Left out: the page's tempo (setGlassTempo), else default, the speed it was made with.

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

number0.6
asChild

Put the glass on the single child element instead of a <button>.

booleanfalse
pull

Hold and drag: the button follows the pointer a little way, stretches along the pull and swings back when let go.

booleantrue
…rest

Passed to the button: onClick, disabled, type, and UI SDK's pendingAnnouncement and focusableWhenDisabled.

button attributes—

Accessibility

  • A real <button> (or your own element with asChild): 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.