# GlassBadge

> A small glass badge with its text flowing through the lens.

```tsx
import { useEffect, useState } from 'react'

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

// A plain card with one orange badge on its corner. Hover the card: the text flows faster.
export default function Demo() {
  // The month we are in, in Turkish. Set after mount: a prerendered page may be months old.
  const [month, setMonth] = useState('Kasım')
  useEffect(() => {
    setMonth(new Intl.DateTimeFormat('tr-TR', { month: 'long' }).format(new Date()))
  }, [])

  return (
    <div className="relative w-full max-w-xs rounded-[28px] border border-neutral-950/15 p-6 dark:border-white/20">
      <p className="font-display text-2xl text-neutral-950 dark:text-white">{month}</p>
      <p className="mt-2 text-sm leading-relaxed text-neutral-600 dark:text-neutral-400">Sliders, switches and checkboxes, now in liquid glass.</p>
      <GlassBadge className="absolute -top-2.5 -right-2.5 bg-orange-600">New</GlassBadge>
    </div>
  )
}
```

**Use it for**

- One short word on a card or a tab: New, Beta, Live.

**Not for**

- Counts or status that must be read at a glance: the text is moving.
- Several on one screen: the motion competes.

```bash
npx shadcn@latest add https://onemorethink.dev/r/badge.json
```

## Usage

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

<div className="relative">
  <Card />
  <GlassBadge className="absolute -top-2 -right-2">New</GlassBadge>
</div>
```

## Behaviour

The text is drawn beneath the glass, so the rim bends the letters as they pass. Whatever sits behind the badge shows through, softly blurred. Hovering the badge's positioned parent speeds the flow up. Colour it with `bg-*` and `text-*`. With `tint` at 0.6 or below the glass counts as clear, and its rim mirrors the colours around it.

## Examples

### Your colours

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

const apps = [
  { name: 'Notes', tile: 'bg-[#ffd60a]', badge: 'bg-neutral-900 text-white', dot: '#ffd60a', label: 'Beta' },
  { name: 'Radio', tile: 'bg-[#ff375f]', badge: 'bg-white text-neutral-900', dot: '#ff375f', label: 'Live' },
  { name: 'Studio', tile: 'bg-[#0a84ff]', badge: 'bg-amber-400 text-neutral-900', dot: '#ffffff', label: 'Pro' },
]

// `bg-*` is the glass colour, `text-*` the flowing text, `dotColor` the separator.
// Each badge sits on the corner of its own tile, so each tile speeds up its own badge.
export default function Demo() {
  return (
    <div className="flex flex-wrap items-start justify-center gap-10">
      {apps.map((app) => (
        <div key={app.name} className="flex flex-col items-center gap-3">
          <div className={`relative size-28 rounded-[30px] ${app.tile}`}>
            <GlassBadge className={`absolute -top-2 -right-3 ${app.badge}`} dotColor={app.dot}>
              {app.label}
            </GlassBadge>
          </div>
          <p className="text-sm font-medium text-neutral-900 dark:text-white">{app.name}</p>
        </div>
      ))}
    </div>
  )
}
```

The badge takes its colour from its own classes: `bg-*` is the glass, `text-*` the text that flows through it, and `dotColor` the square between repeats. Hover speeds up only the badge whose positioned parent is under the pointer.

### A palette

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

const swatches = [
  { label: 'Open', badge: 'bg-emerald-600 text-white', dot: '#a7f3d0' },
  { label: 'Sale', badge: 'bg-rose-600 text-white', dot: '#fecdd3' },
  { label: 'Soon', badge: 'bg-amber-400 text-neutral-900', dot: '#78350f' },
  { label: 'Beta', badge: 'bg-sky-500 text-white', dot: '#e0f2fe' },
  { label: 'Pro', badge: 'bg-violet-600 text-white', dot: '#ddd6fe' },
  { label: 'New', badge: 'bg-neutral-900 text-white dark:bg-white dark:text-neutral-900', dot: '#f97316' },
]

// One badge, six colours: any `bg-*` with a `text-*` that reads on it, and a `dotColor`
// a shade away. Each cell is `relative`, so hovering a cell speeds up only its badge.
export default function Demo() {
  return (
    <div className="grid w-full max-w-md grid-cols-3 gap-2">
      {swatches.map((swatch) => (
        <div key={swatch.label} className="relative flex flex-col items-center gap-4 rounded-3xl bg-white px-4 py-7 dark:bg-neutral-800">
          <GlassBadge className={swatch.badge} dotColor={swatch.dot}>
            {swatch.label}
          </GlassBadge>
          <code className="text-xs text-neutral-500 dark:text-neutral-400">{swatch.badge.split(' ')[0]}</code>
        </div>
      ))}
    </div>
  )
}
```

Any `bg-*` works as the glass. Pair it with a `text-*` that reads on it (dark text on amber, white on the rest) and a `dotColor` a shade away from the text. They sit side by side here only to compare: in a product, keep to one badge per view.

### On a product, for a sale

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

// A rose badge on the corner of a product. Half of it hangs over the yellow cover and
// half over the page, so both show through the glass.
export default function Demo() {
  return (
    <div className="relative w-full max-w-xs">
      <div className="flex aspect-[4/3] items-center justify-center rounded-[28px] bg-[#ffd60a]">
        <span className="flex size-40 items-center justify-center rounded-full bg-neutral-900">
          <span className="flex size-14 items-center justify-center rounded-full bg-[#ff375f]">
            <span className="size-2 rounded-full bg-[#ffd60a]" />
          </span>
        </span>
      </div>
      <div className="mt-4 flex items-baseline justify-between gap-4 px-1">
        <p className="text-[17px] font-semibold tracking-tight text-neutral-900 dark:text-white">Night Drive LP</p>
        <p className="text-[15px] text-neutral-500 tabular-nums dark:text-neutral-400">
          <s>$26</s> <span className="font-semibold text-neutral-900 dark:text-white">$18</span>
        </p>
      </div>
      <GlassBadge className="absolute -top-2.5 -right-2.5 bg-rose-600" dotColor="#ffd60a">
        Sale
      </GlassBadge>
    </div>
  )
}
```

A rose badge hangs off the corner of the cover. Half of it is over the yellow and half over the page, so the glass shows both.

### On a dock item

```tsx
import { House, Library, Search, ShoppingBag } from 'lucide-react'

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

const items = [
  { label: 'Home', icon: House, active: true },
  { label: 'Search', icon: Search },
  { label: 'Library', icon: Library },
  { label: 'Store', icon: ShoppingBag, badge: 'New' },
]

// An orange badge on one item of a dock. The button is `relative`: the badge hangs off
// its corner and speeds up when that button is hovered.
export default function Demo() {
  return (
    <nav aria-label="Dock" className="flex items-center gap-1.5 rounded-full bg-white p-2 dark:bg-neutral-800">
      {items.map((item) => (
        <button
          key={item.label}
          type="button"
          aria-label={item.label}
          className={`relative flex size-14 items-center justify-center rounded-full ${
            item.active ? 'bg-neutral-900 text-white dark:bg-white dark:text-neutral-900' : 'text-neutral-500 dark:text-neutral-400'
          }`}
        >
          <item.icon className="size-6" />
          {item.badge && (
            <GlassBadge className="absolute -top-3 left-8 bg-orange-500" dotColor="#fff7ed">
              {item.badge}
            </GlassBadge>
          )}
        </button>
      ))}
    </nav>
  )
}
```

Put the badge inside the button and give the button `relative`: the orange badge then speeds up when that item is hovered, not the whole dock.

### Clearer glass over colour

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

const bands = ['bg-[#0a84ff]', 'bg-[#ff375f]', 'bg-[#ffd60a]', 'bg-[#30d158]']

// A lower `tint` lets more of the backdrop through: here the bands of the cover show in the
// glass. `speed` sets the pace at rest, and a wider badge (`w-24`) fits a longer word.
export default function Demo() {
  return (
    <div className="relative isolate w-full max-w-sm overflow-hidden rounded-[32px] p-7 pt-36">
      <div aria-hidden className="absolute inset-0 -z-10 flex">
        {bands.map((band) => (
          <span key={band} className={`flex-1 ${band}`} />
        ))}
      </div>
      <p className="text-2xl font-semibold tracking-tight text-white">Colour Fields</p>
      <p className="mt-1 text-[15px] text-white/80">Tonight, 21:00 · Hall B</p>
      <GlassBadge className="absolute top-5 left-5 w-24 bg-black text-white" tint={0.35} speed={0.25} dotColor="#ffd60a">
        Sold out
      </GlassBadge>
    </div>
  )
}
```

`tint` is how much of the badge colour covers what is behind it. At the default `0.82` the badge reads as a solid colour; lower it over a colourful backdrop and the backdrop shows in the glass, softly blurred. `speed` is the pace at rest, in loops per second. The badge is 64 px wide by default: widen it with a `w-*` class for a longer word.

### Inline, next to a label

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

const plans = [
  { name: 'Starter', price: '$0', note: 'One project, community support' },
  { name: 'Team', price: '$24', note: 'Unlimited projects, shared library', badge: 'Popular' },
  { name: 'Scale', price: '$96', note: 'Audit log, SSO and priority support' },
]

// Without a position class the badge flows inline, next to a label. One per list:
// it marks the single row worth a second look. Hover that row and the text speeds up.
export default function Demo() {
  return (
    <ul className="flex w-full max-w-md flex-col gap-2">
      {plans.map((plan) => (
        <li key={plan.name} className="relative flex items-center gap-4 rounded-2xl bg-white px-5 py-4 dark:bg-neutral-800">
          <span className="min-w-0 flex-1">
            <span className="flex items-center gap-2.5">
              <span className="text-[17px] font-semibold tracking-tight text-neutral-900 dark:text-white">{plan.name}</span>
              {plan.badge && (
                <GlassBadge className="w-[72px] bg-violet-600" dotColor="#c4b5fd">
                  {plan.badge}
                </GlassBadge>
              )}
            </span>
            <span className="mt-0.5 block text-sm text-neutral-500 dark:text-neutral-400">{plan.note}</span>
          </span>
          <span className="text-xl font-semibold tracking-tight text-neutral-900 tabular-nums dark:text-white">{plan.price}</span>
        </li>
      ))}
    </ul>
  )
}
```

Without a position class the badge sits in the line like any inline element. Give the row `relative` so the hover that speeds the text up belongs to that row.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `string` | — | The text: one short word. |
| `dotColor` | `string` | `currentColor` | Separator colour between repeats. |
| `speed` | `number` | `0.4` | Loops per second at rest. |
| `tint` | `number` | `0.82` | Opacity of the badge colour over the backdrop. |
| `className` | `string` | — | Position and colour (`bg-*`, `text-*`). |

## Accessibility

- The text is announced once, not as a loop.
- With reduced motion the text stands still, centred.

Source: https://onemorethink.dev/docs/badge
