Badge
A small glass badge with its text flowing through the lens.
Latest change Fixed v2.0.2 Once its glass has drawn, a Badge hides its plain CSS look, but the marquee in that look kept running unseen. It ran on the main thread, so on every frame of anything else on the page the browser worked out all of the page's layers again: several milliseconds a frame, on every page with a Badge. The hidden marquee now stops; without WebGL2 it runs as before.
- v2.0.2 Fixed Once its glass has drawn, a Badge hides its plain CSS look, but the marquee in that look kept running unseen. It ran on the main thread, so on every frame of anything else on the page the browser worked out all of the page's layers again: several milliseconds a frame, on every page with a Badge. The hidden marquee now stops; without WebGL2 it runs as before.
- v1.5.8 Improved A clear badge (
tintat 0.6 or below) now mirrors its surroundings on its rim, as clear buttons do; a badge in its own colour looks the same as before. The first example is now a plain outlined card with one orange badge on its corner. - v1.3.10 Fixed A
text-*class on the badge now always wins over its built-in white. Dark text on a light badge stayed white before: the Live badge in the examples was white on white. - v1.3.7 Improved Three more examples: a palette of six colours, a rose sale badge on a product and an orange badge on a dock item.
- v1.3.3 Improved Three examples: your own colours, clearer glass over a colourful backdrop (
tint,speed, a wider badge), and a badge inline next to a label. - v1.0.0 New A badge whose text flows through the glass.
- All changes→
Kasım
Sliders, switches and checkboxes, now in liquid glass.
NewUse 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.
Installation
npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/badge.jsonNo dependencies Or copy the files by hand →
Usage
app.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.
API reference
| Prop | Type | Default |
|---|---|---|
children The text: one short word. | string | — |
dotColor Separator colour between repeats. | string | currentColor |
speed Loops per second at rest. | number | 0.4 |
tint Opacity of the badge colour over the backdrop. | number | 0.82 |
className Position and colour ( | string | — |
Accessibility
- The text is announced once, not as a loop.
- With reduced motion the text stands still, centred.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.