# GlassButton

> A button made of glass. Clear glass bends the page behind it; tinted glass takes your background colour.

```tsx
import { Play } from 'lucide-react'

import { GlassButton } from '@/components/liquid-glass'

const COLS = 13
const ROWS = 7

/** 1 around the middle of the grid, falling to 0 at its edge. */
const fade = (col: number, row: number) => {
  const distance = Math.hypot((col - (COLS - 1) / 2) / (COLS / 2), (row - (ROWS - 1) / 2) / (ROWS / 2))
  return Math.min(1, Math.max(0, (1 - distance) / 0.45))
}

// Clear glass bends whatever sits behind it: here, only a fine grid centred on the glass,
// on the page's own colour. Watch its lines bend at the rim. The grid is plain DOM: every
// cell draws its own top and left line, fainter the further it is from the glass.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-xl items-center justify-center">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]">
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span key={i} className="relative size-10" style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}>
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassButton size="xl" tint={0} icon={<Play />} iconPosition="start">
        Play
      </GlassButton>
    </div>
  )
}
```

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

```bash
npx shadcn@latest add https://liquidglass.onemorethink.dev/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

```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

```tsx
import { ArrowLeft, ArrowRight, Plus } from 'lucide-react'
import type { ReactNode } from 'react'

import { GlassButton } from '@/components/liquid-glass'

// One row per prop, its values side by side. The buttons of a row sit 10 px apart: hold one
// and pull it towards its neighbour, and under 6 px the two melt into one body.
function Row({ prop, children }: { prop: string; children: ReactNode }) {
  return (
    <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-6">
      <code className="w-20 shrink-0 font-mono text-xs text-neutral-500 dark:text-neutral-400">{prop}</code>
      <div className="relative isolate flex flex-wrap items-center gap-2.5">{children}</div>
    </div>
  )
}

export default function Demo() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-10">
      {/* Clear glass bends the page; tinted glass takes the button's own background class. */}
      <Row prop="material">
        <GlassButton size="lg">Clear</GlassButton>
        <GlassButton size="lg" material="tinted" className="bg-blue-600 text-white">
          Save
        </GlassButton>
        <GlassButton size="lg" material="tinted" className="bg-rose-600 text-white">
          Delete
        </GlassButton>
        <GlassButton size="lg" material="tinted" className="border border-black/15 bg-white text-neutral-900">
          Share
        </GlassButton>
      </Row>

      {/* Clear glass only: 0 lets what lies behind it through, 1 covers it. A flat disc to see it by. */}
      <Row prop="tint">
        <span aria-hidden className="absolute top-6 left-[25px] -z-10 size-20 -translate-y-1/2 rounded-full bg-[#ff6b35]" />
        <GlassButton size="lg" tint={0}>
          0
        </GlassButton>
        <GlassButton size="lg" tint={1}>
          1
        </GlassButton>
      </Row>

      <Row prop="size">
        <GlassButton size="sm" material="tinted" className="bg-emerald-600 text-white">
          sm
        </GlassButton>
        <GlassButton size="md" material="tinted" className="bg-emerald-600 text-white">
          md
        </GlassButton>
        <GlassButton size="lg" material="tinted" className="bg-emerald-600 text-white">
          lg
        </GlassButton>
        <GlassButton size="xl" material="tinted" className="bg-emerald-600 text-white">
          xl
        </GlassButton>
      </Row>

      {/* `icon` with `iconPosition`; an icon alone needs an `aria-label`. */}
      <Row prop="icon">
        <GlassButton size="lg" icon={<ArrowLeft />} iconPosition="start">
          Back
        </GlassButton>
        <GlassButton size="lg" material="tinted" className="bg-violet-600 text-white" icon={<ArrowRight />}>
          Next
        </GlassButton>
        <GlassButton size="lg" material="tinted" aria-label="Add" className="w-12 bg-amber-500 !px-0 text-neutral-950">
          <Plus />
        </GlassButton>
      </Row>

      {/* Held and dragged, a button follows the pointer a little way; `pull={false}` keeps it in place. */}
      <Row prop="pull">
        <GlassButton size="lg" material="tinted" className="bg-neutral-900 text-white dark:bg-white dark:text-neutral-900">
          Hold and drag
        </GlassButton>
        <GlassButton size="lg" pull={false}>
          Stays put
        </GlassButton>
      </Row>
    </div>
  )
}
```

One row per prop, its values next to each other: `material` (clear glass and three colours of tinted glass), `tint` at 0 and 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.

### Tinted colours and sizes

```tsx
import { GlassButton } from '@/components/liquid-glass'

// Tinted glass takes the button's own background class, then adds light and shadow.
// Top row: your colours. Bottom row: the four sizes.
export default function Demo() {
  return (
    <div className="flex flex-col items-center gap-10">
      <div className="flex flex-wrap items-center justify-center gap-3">
        <GlassButton material="tinted" size="lg" className="bg-blue-600 text-white">
          Continue
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-neutral-900 text-white dark:bg-white dark:text-neutral-900">
          Publish
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-rose-600 text-white">
          Delete
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="border border-black/15 bg-white text-neutral-900">
          Cancel
        </GlassButton>
      </div>
      <div className="flex flex-wrap items-center justify-center gap-3">
        <GlassButton material="tinted" size="sm" className="bg-emerald-600 text-white">
          Small
        </GlassButton>
        <GlassButton material="tinted" size="md" className="bg-emerald-600 text-white">
          Medium
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-emerald-600 text-white">
          Large
        </GlassButton>
        <GlassButton material="tinted" size="xl" className="bg-emerald-600 text-white">
          Extra large
        </GlassButton>
      </div>
    </div>
  )
}
```

Colour tinted glass with a normal class such as `bg-sky-500`; the glass paints itself in that colour and adds light and shadow. A `border-*` class becomes the glass rim.

### As a link (asChild)

```tsx
import { ArrowUpRight } from 'lucide-react'

import { GlassButton } from '@/components/liquid-glass'

// `asChild` puts the glass on your own element. The same works with a Next.js or
// TanStack Router <Link>: it stays a real link with its own navigation.
export default function Demo() {
  return (
    <div className="flex flex-col items-center gap-6 text-center">
      <div>
        <p className="text-3xl font-semibold tracking-tight text-neutral-900 dark:text-white">Free and open source</p>
        <p className="mt-2 text-base text-neutral-500 dark:text-neutral-400">MIT licensed. Copy the files, they are yours.</p>
      </div>
      <GlassButton asChild material="tinted" size="lg" icon={<ArrowUpRight />} className="bg-violet-600 text-white">
        <a href="https://github.com/bilalgursen/liquid-glass" target="_blank" rel="noreferrer">
          Star on GitHub
        </a>
      </GlassButton>
    </div>
  )
}
```

With `asChild` the glass goes on your single child element instead of a `<button>`: an `<a>`, a Next.js `<Link>`, a TanStack Router `<Link>`. Your element keeps its own props and navigation.

### Over colour with a scrim

```tsx
import { ArrowRight, Play } from 'lucide-react'

import { GlassButton } from '@/components/liquid-glass'

// Clear glass over colour. The backdrop is plain DOM: flat discs of colour on a dark scene
// and a dark scrim over them. The glass sees both, and the text, so the buttons sit in the scene.
export default function Demo() {
  return (
    <div className="relative isolate flex h-96 w-full max-w-2xl flex-col items-start justify-end overflow-hidden rounded-3xl bg-[#0b1030] p-8">
      <div aria-hidden className="absolute inset-0 -z-20">
        <span className="absolute -top-24 -left-16 size-80 rounded-full bg-[#22d3ee]" />
        <span className="absolute -top-32 right-4 size-72 rounded-full bg-[#a855f7]" />
        <span className="absolute -right-20 -bottom-28 size-96 rounded-full bg-[#ec4899]" />
        <span className="absolute -bottom-40 left-24 size-80 rounded-full bg-[#1d4ed8]" />
      </div>
      <div aria-hidden className="absolute inset-0 -z-10 bg-black/35" />
      <p className="text-xs font-semibold tracking-[0.18em] text-white/70">TROMSØ · WINTER SEASON</p>
      <h3 className="mt-2 max-w-sm text-4xl leading-[1.05] font-semibold tracking-tight text-white">Chase the northern lights</h3>
      <div className="mt-6 flex flex-wrap gap-3">
        <GlassButton size="lg" tint={0.35} icon={<ArrowRight />}>
          Plan the trip
        </GlassButton>
        <GlassButton size="lg" tint={0.15} icon={<Play />} iconPosition="start">
          Watch the film
        </GlassButton>
      </div>
    </div>
  )
}
```

Clear glass repaints what lies behind it: background colours, gradients and images, `<img>` and `<video>` the way the page crops them (`object-fit`), text, inline SVG icons and backdrop blur, in their stacking order. Shadows, `::before`/`::after` and conic gradients are not painted.

> An image from another origin must be served with CORS headers (image CDNs usually send them): the glass requests it again with CORS, and leaves it out if the server refuses.

### Square corners

```tsx
import { Plus } from 'lucide-react'

import { GlassButton } from '@/components/liquid-glass'

// The glass takes the button's own corners: add a `rounded-*` class and the lens follows.
// Fine ruled lines show the bend running along the straight edges and around each corner.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-2xl flex-wrap items-center justify-center gap-4 overflow-hidden rounded-3xl">
      <div aria-hidden className="absolute inset-0 -z-10 flex flex-col justify-between">
        {Array.from({ length: 33 }, (_, i) => (
          <span key={i} className="h-px bg-black/10 dark:bg-white/10" />
        ))}
      </div>
      <GlassButton size="xl" tint={0.3} className="rounded-2xl" icon={<Plus />} iconPosition="start">
        New project
      </GlassButton>
      <GlassButton size="xl" material="tinted" className="rounded-2xl bg-neutral-900 text-white dark:bg-white dark:text-neutral-900">
        Open
      </GlassButton>
    </div>
  )
}
```

The glass takes the corners of the element it sits on. Add a `rounded-*` class and the lens, its rim and its shadow follow; the bend stays as deep as on a pill.

### Hold and drag (pull)

```tsx
import { Mic, Plus } from 'lucide-react'

import { GlassButton } from '@/components/liquid-glass'

const TICKS = 61

// Hold a button and drag away (`pull`, on by default). It comes after the pointer a little way through a rubber
// band, stretches along the pull and thins across it, and swings back like gel when you let go.
// The round ones are small, so they follow from the very point you pressed; the wide one waits
// until the pointer is past its edge. Behind them a ruler to read the stretch against: plain
// DOM, one thin line per tick, fainter towards the ends.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-xl items-center justify-center gap-4 overflow-hidden">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 flex -translate-x-1/2 -translate-y-1/2 items-center gap-[7px]">
        {Array.from({ length: TICKS }, (_, i) => (
          <span
            key={i}
            className={`w-px bg-black/15 dark:bg-white/15 ${i % 10 === 0 ? 'h-28' : i % 5 === 0 ? 'h-20' : 'h-10'}`}
            style={{ opacity: Math.min(1, (1 - Math.abs(i - (TICKS - 1) / 2) / ((TICKS - 1) / 2)) / 0.4) }}
          />
        ))}
      </div>
      <GlassButton size="lg" tint={0.2} aria-label="Add" className="w-12 !px-0">
        <Plus />
      </GlassButton>
      <GlassButton size="lg" tint={0.2}>
        Hold and drag
      </GlassButton>
      <GlassButton size="lg" material="tinted" aria-label="Record" className="w-12 bg-neutral-900 !px-0 text-white dark:bg-white dark:text-neutral-900">
        <Mic />
      </GlassButton>
    </div>
  )
}
```

A pointer that holds the button and drags away pulls it after itself. The button follows a little way through a rubber band (10 px at most on a wide button), stretches along the pull and thins across it, and swings back like gel when you let go. A button up to 72 px follows from the point it was pressed at; a wider one moves only once the pointer is past its edge. On by default (`pull={false}` keeps the button in its place), and still under reduced motion. Let go outside the button and nothing is clicked, as with any button.

Two buttons that come near each other melt into one body, as two drops of liquid do: pull the round button towards the wide one above. Within reach the sides that face each other lean out, nearer still a bridge forms, and it thins and lets go as they part. They begin to melt once the gap between them is under 6 px, and join under half of that (`COHESION` in `engine.ts`). Joined, hold one and part of its light runs on into the other. Every button of the kit does it, Action Button and Button Group included; a card, a menu or a lens never melts.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `material` | `'clear' \| 'tinted'` | `'clear'` | Clear bends the page; tinted uses the background colour. |
| `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Height 32, 40, 48 or 64 px. |
| `icon` | `ReactNode` | — | An icon element (e.g. a lucide-react icon). |
| `iconPosition` | `'start' \| 'end'` | `'end'` | Which side the icon sits on. |
| `tint` | `number` | `0.6` | Clear glass only: how much tint covers the backdrop (0–1). |
| `asChild` | `boolean` | `false` | Put the glass on the single child element instead of a `<button>`. |
| `pull` | `boolean` | `true` | Hold and drag: the button follows the pointer a little way, stretches along the pull and swings back when let go. |
| `…rest` | `button attributes` | — | Passed to the button: `onClick`, `disabled`, `type`, and UI SDK's `pendingAnnouncement` and `focusableWhenDisabled`. |

## 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`.

Source: https://liquidglass.onemorethink.dev/docs/button
