# Badge

A compact label with independent appearance and color.

Badge separates **appearance** from **color**. Use `variant` to choose the surface treatment and `color` to choose a semantic intent or named palette.

```tsx
import { Badge, Stack } from "@zentara-co/zenos-ui";

const badgeVariants = ["default", "outline", "solid", "soft"] as const;

function BadgePreviewExample() {
  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap" className="justify-center">
      {badgeVariants.map((variant) => (
        <Badge key={variant} variant={variant} color="blue">
          {variant}
        </Badge>
      ))}
    </Stack>
  );
}
```

## Import

```tsx
import { Badge, type BadgeColor, type BadgeVariant } from "@zentara-co/zenos-ui";
```

## Appearance variants

- **default:** A tinted surface with a matching border.
- **outline:** A transparent surface with a colored outline.
- **solid:** A strong fill with a contrasting foreground and a richer dark-mode surface.
- **soft:** A low-emphasis fill without a visible border.

Every appearance supports the same colors. Omitting both props gives `variant="default"` and `color="neutral"`. Neutral default and outline badges use visible gray surfaces and borders instead of low-opacity white or black.

```tsx
import { Badge, Stack, Text } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

const badgeVariants = ["default", "outline", "solid", "soft"] as const;

const badgeColors = [
  "neutral",
  "brand",
  "danger",
  "warning",
  "information",
  "success",
  "gray",
  "red",
  "orange",
  "yellow",
  "lime",
  "green",
  "teal",
  "cyan",
  "sky",
  "blue",
  "indigo",
  "purple",
  "pink",
] as const;

function BadgeVariantsExample({ limit }: CatalogVariantProps = {}) {
  if (limit !== undefined) {
    return (
      <Stack direction="row" gap="2" align="center" wrap="wrap" className="justify-center">
        {limited(badgeVariants, limit).map((variant) => (
          <Badge key={variant} variant={variant} color="blue">
            {variant}
          </Badge>
        ))}
      </Stack>
    );
  }
  return (
    <Stack gap="5" className="w-full">
      {badgeVariants.map((variant) => (
        <Stack key={variant} gap="2">
          <Text as="h3" type="emphasis" size="s" color="subtle">
            {variant}
          </Text>
          <Stack direction="row" gap="2" align="center" wrap="wrap">
            {badgeColors.map((color) => (
              <Badge key={color} variant={variant} color={color}>
                {color}
              </Badge>
            ))}
          </Stack>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Colors

Choose an intent with `neutral`, `brand`, `danger`, `warning`, `information`, or `success`. For categorical distinctions, choose `gray`, `red`, `orange`, `yellow`, `lime`, `green`, `teal`, `cyan`, `sky`, `blue`, `indigo`, `purple`, or `pink`.

Color and appearance are independent: for example, `variant="outline" color="danger"` and `variant="soft" color="danger"` share an intent but have different emphasis. The palettes use mode-aware semantic tokens.

```tsx
import { Badge, Stack } from "@zentara-co/zenos-ui";

const badgeColors = [
  "neutral",
  "brand",
  "danger",
  "warning",
  "information",
  "success",
  "gray",
  "red",
  "orange",
  "yellow",
  "lime",
  "green",
  "teal",
  "cyan",
  "sky",
  "blue",
  "indigo",
  "purple",
  "pink",
] as const;

function BadgeColorsExample() {
  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      {badgeColors.map((color) => (
        <Badge key={color} variant="soft" color={color}>
          {color}
        </Badge>
      ))}
    </Stack>
  );
}
```

## Shape

Use `rounded` for fully rounded corners, or `rounded={false}` for regular corners. Badge defaults to `false`. Shape is independent of `variant` and `color`, including custom variants. Custom classes can still override the corner radius.

```tsx
import { Badge, Stack } from "@zentara-co/zenos-ui";

function BadgeShapeExample() {
  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      <Badge variant="soft" color="blue" rounded={false}>
        Regular corners
      </Badge>
      <Badge variant="soft" color="blue" rounded>
        Fully rounded
      </Badge>
    </Stack>
  );
}
```

## With icons

Use `Badge.Icon` for decorative leading or trailing icons. The wrapper hides its contents from assistive technology so the badge text remains the accessible label. `Badge.Root` is an alias for `Badge`.

```tsx
import { CheckCircleIcon } from "@phosphor-icons/react";
import { Badge, Stack } from "@zentara-co/zenos-ui";

function BadgeIconExample() {
  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      <Badge color="success">
        <Badge.Icon>
          <CheckCircleIcon />
        </Badge.Icon>
        Verified
      </Badge>
      <Badge variant="outline" color="success">
        Active
        <Badge.Icon>
          <CheckCircleIcon />
        </Badge.Icon>
      </Badge>
    </Stack>
  );
}
```

## As a link

Use `render={<a href="…" />}` when a label navigates to another page or section. Badge renders that anchor instead of a wrapping span, preserving `variant`, `color`, `rounded`, custom styling, hover feedback, and a visible keyboard focus ring. Without `render`, `Badge` and `Badge.Root` remain noninteractive spans.

```tsx
import { CheckCircleIcon } from "@phosphor-icons/react";
import { Badge, Stack } from "@zentara-co/zenos-ui";

function BadgeLinkExample() {
  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      <Badge
        render={<a href="/components/badge/#appearance-variants" />}
        variant="outline"
        color="blue"
      >
        Explore appearances
      </Badge>
      <Badge render={<a href="/components/badge/#shape" />} variant="soft" color="purple" rounded>
        <Badge.Icon>
          <CheckCircleIcon />
        </Badge.Icon>
        Explore shapes
      </Badge>
    </Stack>
  );
}
```

Put native anchor props such as `href`, `target`, `rel`, `download`, and `aria-current` on the element passed to `render`. Base UI merges its classes, styles, event handlers, and ref with Badge's props. Use `Badge.Icon` for decorative icons inside a link. For a new tab, pair `target="_blank"` with `rel="noopener noreferrer"` and make that behavior clear in the link text.

You can also pass your router's link component through `render`, provided it forwards props and its ref to the underlying anchor. A render callback is supported when you need to construct the element yourself; spread the supplied props onto that element so styling, accessibility attributes, and refs are preserved.

## Custom styling

Like [Button](/components/button/#custom-styling), Badge accepts your own appearance through the usual `className` prop. You do not need to supply `variant`, `color`, or `variantClassName`. Your classes apply last and override conflicting built-in styles while keeping the base layout, icon sizing, and native behavior.

Define the background, border, foreground, shape, and spacing you want to replace, using semantic tokens for theme-aware colors. Layout-only classes keep the default appearance, and native `style` props remain available. Built-in `variant` and `color` props are optional conveniences, not requirements for custom styling.

```tsx
import { Badge, Stack } from "@zentara-co/zenos-ui";

function CustomBadgeVariantExample() {
  const campaignBadgeClassName =
    "rounded-full border-transparent bg-background-accent-purple-bolder-hover px-3 text-text-contrary";

  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      <Badge className={campaignBadgeClassName}>Campaign</Badge>
      <Badge className="rounded-full border-transparent bg-background-success-default px-3 text-text-success-bolder">
        Ready
      </Badge>
    </Stack>
  );
}
```

The same `className` approach works with `render` links. Share a class string or an application CSS class when you want to reuse a custom appearance.

For a compact uppercase category label, use [Status Pill](/components/status-pill/).

## Anatomy

```text
Badge
Badge.Root
Badge.Link
Badge.Icon
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| className | string | — | Custom styling and instance overrides. No variant or color prop is required. |
| render | ReactElement \| ((props, state) => ReactElement) | — | Replace the default span with an anchor or router link. Base UI merges props, handlers, and refs. |
| rounded | boolean | false | Fully rounded corners when true; regular corners when false. |
| variant | BadgeVariant | default | default, outline, solid, soft, or a consumer-owned appearance name. |
| variantClassName | string | — | Optional classes for existing named-variant integrations. Use className for custom styling. |
| color | BadgeColor | neutral | Semantic intent or named color palette, independent of appearance. |
| native props | React.HTMLAttributes<HTMLSpanElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |
| href | string | — | Navigation destination on the anchor passed to render. Also supported by Badge.Link. |
| anchor props | AnchorHTMLAttributes<HTMLAnchorElement> | — | Badge.Link forwards native anchor attributes and an HTMLAnchorElement ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Badge renders a native `span` by default, not an interactive control or an automatic live region. When using `render` with a link, supply an `href` and descriptive link text, and keep its keyboard focus indicator visible. Do not nest interactive elements inside it or use it for actions that belong on a button. Keep text concise and do not rely on color alone to communicate meaning. Use `role="status"` on a noninteractive label only when the content actually needs a polite live announcement.

Source: https://zenos-ui.pages.dev/components/badge/