Skip to content

Badge

Small status and metadata component used to label, categorize, or highlight information in PyColors UI.

The Badge component is a compact, non-interactive UI primitive used to display short information such as status, category, count, or label.

Badges are lightweight, semantic, and fully aligned with the PyColors design system tokens. They are designed for metadata, not actions.


Import

import { Badge } from "@pycolors/ui"

Basic usage

Default
<Badge>Default</Badge>
import { Badge } from "@pycolors/ui";

export default function Demo() {
  return <Badge>Default</Badge>;
}

Badges inherit their colors from semantic tokens and adapt automatically to light and dark mode.


Variants

Use variants to convey meaning or status.

DefaultSecondaryMutedOutlineSuccessWarningDestructive
  <Badge>Default</Badge>
  <Badge variant="secondary">Secondary</Badge>
  <Badge variant="muted">Muted</Badge>
  <Badge variant="outline">Outline</Badge>
  <Badge variant="success">Success</Badge>
  <Badge variant="warning">Warning</Badge>
  <Badge variant="destructive">Destructive</Badge>
import { Badge } from "@pycolors/ui";

export default function BadgeVariantsExample() {
  return (
    <div className="flex gap-2">
      <Badge>Default</Badge>
      <Badge variant="secondary">Secondary</Badge>
      <Badge variant="muted">Muted</Badge>
      <Badge variant="outline">Outline</Badge>
      <Badge variant="success">Success</Badge>
      <Badge variant="warning">Warning</Badge>
      <Badge variant="destructive">Error</Badge>
    </div>
  );
}

Available variants

VariantDescription
defaultPrimary or neutral label
secondarySecondary emphasis
mutedLow-contrast metadata
outlineNeutral bordered label
successPositive or completed state
warningCaution or attention required
destructiveError or critical state

Sizes

SmallDefaultLarge
<Badge size="sm">Small</Badge>
<Badge size="md">Default</Badge>
<Badge size="lg">Large</Badge>
import { Badge } from "@pycolors/ui";

export default function BadgeSizes() {
  return (
    <div className="flex gap-2">
      <Badge size="sm">Small</Badge>
      <Badge size="md">Default</Badge>
      <Badge size="lg">Large</Badge>
    </div>
  );
}

Available sizes

SizeDescription
smCompact metadata
mdDefault badge size
lgEmphasized or prominent

With icon

Badges can include icons when needed (status, type, category).

Active

<Badge variant="success">
  <CheckIcon className="size-3" />
  Active
</Badge>
import { Badge } from "@pycolors/ui";

export default function BadgeWithIcon() {
  return (
    <Badge variant="success">
      <svg className="size-3" viewBox="0 0 24 24">
        <path d="M5 13l4 4L19 7" />
      </svg>
      Active
    </Badge>
  );
}

As child (Slot)

Use asChild to render a badge as another element (for example, a link).

<Badge asChild>
  <a href="/docs">Docs</a>
</Badge>
import { Badge } from "@pycolors/ui";

export default function BadgeAsChild() {
  return (
    <Badge asChild>
      <a href="/docs">Docs</a>
    </Badge>
  );
}

API

Props

PropTypeDefaultDescription
variantBadgeVariant"default"Visual style
sizeBadgeSize"md"Badge size
asChildbooleanfalseRender via Radix Slot
classNamestringAdditional Tailwind classes

The Badge extends standard HTML span props:

React.HTMLAttributes<HTMLSpanElement>

TypeScript types

export type BadgeVariant =
  | "default"
  | "secondary"
  | "muted"
  | "outline"
  | "success"
  | "warning"
  | "destructive";

export type BadgeSize =
  | "sm"
  | "md"
  | "lg";

Accessibility

  • Badges are decorative by default and should not replace buttons.
  • Do not rely on color alone to convey meaning.
  • When clickable, use asChild with a semantic element (a, button).
  • Icons must be supplementary and not the sole indicator.

Design guidelines

  • Use muted or outline for metadata and low-emphasis labels.
  • Use success, warning, and destructive only for status indicators.
  • Avoid overusing badges—prefer clarity over decoration.
  • Keep badge text short (1–2 words whenever possible).