Badge

A small label, like a status.

BadgeSecondaryDestructiveOutline
badge-demo.tsx
import { Badge } from './ui/badge.tsx'

export default () => (
  <>
    <Badge>Badge</Badge>
    <Badge variant="secondary">Secondary</Badge>
    <Badge variant="destructive">Destructive</Badge>
    <Badge variant="outline">Outline</Badge>
  </>
)

Installation

dui add badge

Or copy ui/badge.tsx and ui/badge.css into your project, with lib/jsx/jsx-runtime.ts, lib/jsx/jsx-dev-runtime.ts, lib/css.d.ts, and lib/theme.css.

Examples

With an icon, and as a count

Verified899+
badge-icon.tsx
import { Badge } from './ui/badge.tsx'

export default () => (
  <>
    <Badge variant="secondary">
      <svg
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M20 6 9 17l-5-5" />
      </svg>
      Verified
    </Badge>
    <Badge style="min-width: 1.25rem; border-radius: 9999px; padding-inline: 0.25rem">8</Badge>
    <Badge
      variant="destructive"
      style="min-width: 1.25rem; border-radius: 9999px; padding-inline: 0.25rem"
    >
      99+
    </Badge>
  </>
)
badge-link.tsx
import { Badge } from './ui/badge.tsx'

// With an href, it's an <a>.
export default () => (
  <Badge href="/docs/components/badge" variant="outline">
    Link
  </Badge>
)

Compared to shadcn/ui