Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Badge for Astro

Small Astro labels for status, category, and counts.

default
default
default
secondary
secondary
secondary
success
success
success
warning
warning
warning
info
info
info
destructive
destructive
destructive
error
error
error
outline
outline
outline
ghost
ghost
ghost

Installation

bunx --bun shadcn@latest add @gnostic/badge

Usage

import { Badge } from "@/components/ui/badge"
<Badge variant="default">Badge</Badge>

Use the polymorphic as prop to render the badge as a link element.

---
import { Badge } from "@/components/ui/badge"
---

<Badge as="a" href="/">Badge</Badge>

Polymorphic

Badge is strict polymorphic. Pass as to change the rendered element and use attributes for that element.

<Badge as="button" type="button">Action</Badge>
<Badge as="a" href="/docs">Docs</Badge>

Notes

  • Use variants first before adding custom classes.
  • Badge works well for status labels, counts, and small inline metadata.

Shape

shape accepts default and rounded. default keeps the badge radius. rounded makes a pill.

DefaultRounded

With an icon

Put a check icon in the badge. The badge sets the icon size.

Verified Verified Verified

With a count

Set shape to rounded when the badge shows a notification count.

8 3 12

Badge group

Put a badge at the start or end of a short label.

API Reference

Read the installed source for the complete prop types.

When to use Badge

Use Badge for a short fact attached to another object. Keep the text brief and choose a semantic variant only when the meaning is clear. The size prop changes density. The shape prop changes the radius.

Keyboard and behavior

A badge is a label, not an action by default. Do not depend on its color alone to communicate status. If you make it a link through its supported element props, use a clear destination label and keep the focus style.

Theme and layout

The variants share semantic color tokens with alerts and buttons. Test the small size with the actual label text. Long sentences belong in a description or alert instead of a badge.