Badge
Status and counts, with a dot, a pulse or a remove button.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add badgeOr install the package
Don’t want the file? Import from
asta-ui/badgeand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { Badge } from "asta-ui/badge";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import type { HTMLAttributes, ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type BadgeVariant = "solid" | "soft" | "outline"; export type BadgeTone = "neutral" | "accent" | "success" | "warning" | "danger"; // One colour per tone; the variants mix it into fill, text and ring. const TONE: Record<BadgeTone, string> = { neutral: "var(--color-ink)", accent: "var(--color-brand)", success: "var(--color-brand)", warning: "var(--color-ink-2)", danger: "var(--color-ink)", }; const VARIANT: Record<BadgeVariant, string> = { solid: "bg-[var(--kit-badge)] text-[var(--kit-badge-on)]", soft: "bg-[color-mix(in_srgb,var(--kit-badge)_12%,transparent)] text-[color-mix(in_srgb,var(--kit-badge)_80%,var(--color-ink))]", outline: "text-[color-mix(in_srgb,var(--kit-badge)_80%,var(--color-ink))] shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--kit-badge)_35%,transparent)]", }; export interface BadgeProps extends Omit<HTMLAttributes<HTMLSpanElement>, "children"> { variant?: BadgeVariant; tone?: BadgeTone; /** A small dot before the label. */ dot?: boolean; /** The dot breathes, for live states ("Online", "Deploying"). */ pulse?: boolean; /** Shows a remove button and calls this when it's pressed. */ onRemove?: () => void; size?: "sm" | "md"; children?: ReactNode; } export function Badge({ variant = "soft", tone = "neutral", dot, pulse, onRemove, size = "md", className, style, children, ...rest }: BadgeProps) { const on = tone === "accent" || tone === "success" ? "var(--color-on-brand)" : "var(--color-paper)"; return ( <span {...rest} style={{ ["--kit-badge" as string]: TONE[tone], ["--kit-badge-on" as string]: on, ...style }} className={cx( "inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md font-medium tracking-[-0.005em]", size === "sm" ? "h-5 px-2 text-[11px]" : "h-6 px-2.5 text-[12px]", onRemove && (size === "sm" ? "pr-0.5" : "pr-1"), VARIANT[variant], className, )} > {(dot || pulse) && ( <span className="relative flex h-1.5 w-1.5 shrink-0"> {pulse && <span className="absolute inset-0 animate-[kit-badge-ping_1.6s_cubic-bezier(.16,1,.3,1)_infinite] rounded-full bg-current motion-reduce:hidden" />} <span className={cx("relative h-1.5 w-1.5 rounded-full", variant === "solid" ? "bg-current" : "bg-[var(--kit-badge)]")} /> </span> )} {children} {onRemove && ( <button type="button" onClick={onRemove} aria-label={typeof children === "string" ? `Remove ${children}` : "Remove"} className={cx( "inline-flex items-center justify-center rounded-full opacity-60 outline-none transition-[opacity,background-color] hover:bg-[color-mix(in_srgb,currentColor_15%,transparent)] hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-brand/50", size === "sm" ? "h-4 w-4" : "h-[18px] w-[18px]", )} > <svg viewBox="0 0 24 24" className="h-2.5 w-2.5" fill="none" stroke="currentColor" strokeWidth="3.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 6 12 12" /> <path d="M18 6 6 18" /> </svg> </button> )} <style href="asta-badge" precedence="asta">{`@keyframes kit-badge-ping { 0% { transform: scale(1); opacity: .7 } 100% { transform: scale(3); opacity: 0 } }`}</style> </span> ); } /** A count bubble for icons and tabs. Caps at `max` ("99+"). */ export function CountBadge({ count, max = 99, className }: { count: number; max?: number; className?: string }) { if (count <= 0) return null; return ( <span key={count} className={cx( "inline-flex h-[18px] min-w-[18px] animate-[kit-badge-pop_.4s_cubic-bezier(.16,1,.3,1)] items-center justify-center rounded-[5px] bg-ink px-1 text-[10.5px] font-semibold tabular-nums leading-none text-white shadow-[0_0_0_2px_var(--color-paper)] motion-reduce:animate-none", className, )} > {count > max ? `${max}+` : count} <style href="asta-badge-2" precedence="asta">{`@keyframes kit-badge-pop { 0% { transform: scale(.4) } 60% { transform: scale(1.15) } 100% { transform: scale(1) } }`}</style> </span> ); } export default Badge;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Badge component to my project. Status and counts, with a dot, a pulse or a remove button. It includes: solid, soft, outline, dot, pulse, removable. Install it: ```sh pnpm dlx asta-ui@latest add badge --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/badge.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Badge, CountBadge } from "@/components/astabyte/badge"; ``` Usage example and props: https://ui.astabyte.com/badge Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:flex;flex-wrap:wrap;gap:10px;align-items:center"> <span class="asta-badge">Draft</span> <span class="asta-badge asta-badge-accent"><span class="asta-badge-dot"></span>Beta</span> <span class="asta-badge asta-badge-success asta-badge-solid"><span class="asta-badge-dot"><span class="asta-badge-ping"></span></span>Live</span> <span class="asta-badge asta-badge-warning asta-badge-outline">Pending</span> <span class="asta-badge asta-badge-danger">Failed</span> <span class="asta-badge asta-badge-accent">astabyte<button type="button" class="asta-badge-remove" aria-label="Remove"><svg viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M3 3l6 6M9 3l-6 6"/></svg></button></span> <span class="asta-count">3</span> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { Badge, CountBadge } from "@/components/astabyte/badge";
const Row = ({ label, children }: { label: string; children: React.ReactNode }) => (
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
<span className="w-20 shrink-0 font-mono text-[11px] uppercase tracking-wider text-mute">{label}</span>
<div className="flex flex-wrap items-center gap-2">{children}</div>
</div>
);
const TAGS = ["Design", "React", "Motion", "Tailwind"];
export default function BadgeDemo() {
const [tags, setTags] = useState(TAGS);
const [inbox, setInbox] = useState(3);
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex flex-col gap-6">
<Row label="Solid">
<Badge variant="solid">Neutral</Badge>
<Badge variant="solid" tone="accent">New</Badge>
<Badge variant="solid" tone="success">Paid</Badge>
<Badge variant="solid" tone="warning">Pending</Badge>
<Badge variant="solid" tone="danger">Failed</Badge>
</Row>
<Row label="Soft">
<Badge>Draft</Badge>
<Badge tone="accent">Beta</Badge>
<Badge tone="success">Active</Badge>
<Badge tone="warning">Review</Badge>
<Badge tone="danger">Overdue</Badge>
</Row>
<Row label="Outline">
<Badge variant="outline">v2.4.0</Badge>
<Badge variant="outline" tone="accent" dot>
Preview
</Badge>
<Badge variant="outline" tone="success" dot>
Shipped
</Badge>
</Row>
<Row label="Live">
<Badge tone="success" pulse>
Online
</Badge>
<Badge tone="accent" pulse>
Deploying
</Badge>
<Badge variant="solid" tone="danger" pulse>
Live
</Badge>
</Row>
<Row label="Remove">
{tags.map((t) => (
<Badge key={t} variant="outline" onRemove={() => setTags((x) => x.filter((y) => y !== t))}>
{t}
</Badge>
))}
{tags.length < TAGS.length && (
<button type="button" onClick={() => setTags(TAGS)} className="text-[12px] text-mute underline-offset-4 hover:text-ink hover:underline">
Reset
</button>
)}
</Row>
<Row label="Count">
<button
type="button"
onClick={() => setInbox((n) => n + 1)}
className="relative inline-flex h-10 items-center gap-2 rounded-lg bg-paper px-4 text-[14px] font-medium shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)] outline-none transition-transform active:scale-[0.97] focus-visible:ring-2 focus-visible:ring-brand/50"
>
Inbox
<CountBadge count={inbox} />
</button>
<span className="text-[12px] text-mute">Click to get mail</span>
</Row>
</div>
</div>
);
}