# Tag

A compact token with optional icon and removal action.

Use Tag for compact tokens such as selected filters, categories, or people. Add an icon or a removal action when needed. For a read-only label, use [Badge](/components/badge/); for an operational state, use [Status Pill](/components/status-pill/). Use [Tag Input](/components/tag-input/) to manage tags inside an input field.

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

function TagPreviewExample() {
  return (
    <Stack direction="row" gap="3" align="center" wrap="wrap">
      <Tag>Research</Tag>
      <Tag appearance="rounded">Design</Tag>
      <Tag.Root label="Production">
        <Tag.Icon>
          <span className="size-2 rounded-full bg-current" />
        </Tag.Icon>
        <Tag.Label>Production</Tag.Label>
      </Tag.Root>
    </Stack>
  );
}
```

## Import

```tsx
import { Tag } from "@zentara-co/zenos-ui";
```

## Appearance

The default appearance is a compact, 20px-high tag with slightly rounded corners. Set `appearance="rounded"` for a 24px-high pill. Appearance and color are independent.

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

function TagAppearanceExample() {
  return (
    <Stack direction="row" gap="3" align="center" wrap="wrap">
      <Tag appearance="default">Compact</Tag>
      <Tag appearance="rounded">Rounded</Tag>
    </Stack>
  );
}
```

## Colors

Tags use the neutral palette by default. Choose an accent with `color`, or its lighter counterpart with the `-light` suffix. The ten accent hues are blue, red, yellow, green, teal, purple, gray, lime, orange, and magenta. These palettes use semantic background and text tokens for both themes.

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

function TagColorsExample() {
  const colors = [
    "neutral",
    "blue",
    "blue-light",
    "red",
    "red-light",
    "yellow",
    "yellow-light",
    "green",
    "green-light",
    "teal",
    "teal-light",
    "purple",
    "purple-light",
    "gray",
    "gray-light",
    "lime",
    "lime-light",
    "orange",
    "orange-light",
    "magenta",
    "magenta-light",
  ] as const;

  return (
    <Stack direction="row" gap="2" align="center" wrap="wrap">
      {colors.map((color) => (
        <Tag key={color} color={color}>
          {color}
        </Tag>
      ))}
    </Stack>
  );
}
```

## Removable tags

Pass `onRemove` to `Tag` to add a remove button. The parent owns the selected values and removes the tag from its list; Tag does not remove itself. Plain-text children are included in the button's accessible name automatically.

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

function TagRemovableExample() {
  const [tags, setTags] = useState(["Security", "Infrastructure", "Production"]);

  return (
    <Stack gap="3" align="start">
      <Stack direction="row" gap="2" wrap="wrap">
        {tags.map((tag) => (
          <Tag key={tag} onRemove={() => setTags(tags.filter((currentTag) => currentTag !== tag))}>
            {tag}
          </Tag>
        ))}
      </Stack>
      <Text size="s" color="subtle" aria-live="polite">
        {tags.length === 0 ? "No filters selected." : `${tags.length} filters selected.`}
      </Text>
    </Stack>
  );
}
```

### Accessible removal labels

For rich content, supply `label` so the default button name identifies the tag. This prop describes the remove action; it does not render visible text. Use `removeLabel` to override the complete button name when more context is helpful.

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

function TagRemoveLabelExample() {
  const [selected, setSelected] = useState(true);

  return (
    <Stack gap="3" align="start">
      {selected && (
        <Tag
          label="Design team"
          removeLabel="Remove Design team filter"
          onRemove={() => setSelected(false)}
        >
          <span>
            Design <strong>team</strong>
          </span>
        </Tag>
      )}
      <Text size="s" color="subtle" aria-live="polite">
        {selected ? "Design team filter selected." : "Design team filter removed."}
      </Text>
    </Stack>
  );
}
```

## Compound composition

Use `Tag.Root`, `Tag.Icon`, `Tag.Label`, and `Tag.Remove` for explicit composition. Unlike `Tag`, `Tag.Root` does not add a label wrapper or remove button automatically: include those parts yourself and pass `onRemove` to the root.

`Tag.Icon` is decorative and hidden from assistive technology. `Tag.Label` truncates when its container has a constrained width. Setting `disabled` on the root dims the tag and disables its remove button.

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

function TagCompoundExample() {
  return (
    <Stack direction="row" gap="3" wrap="wrap" align="center">
      <Tag.Root label="Production" onRemove={() => undefined}>
        <Tag.Icon>
          <span className="size-2 rounded-full bg-current" />
        </Tag.Icon>
        <Tag.Label>Production</Tag.Label>
        <Tag.Remove />
      </Tag.Root>
      <Tag.Root className="max-w-44 border-border-default bg-transparent">
        <Tag.Label>Extremely long environment name that truncates safely</Tag.Label>
      </Tag.Root>
      <Tag.Root label="Managed" disabled onRemove={() => undefined}>
        <Tag.Label>Managed</Tag.Label>
        <Tag.Remove />
      </Tag.Root>
    </Stack>
  );
}
```

## Custom styling

Use the usual `className` prop for your own styling. You do not need to pass `appearance`, `color`, or `variant` to customize a tag. Conflicting utility classes override the built-in appearance and palette. Each compound part also accepts `className`, native props, and a ref.

```tsx
import { Tag } from "@zentara-co/zenos-ui";

function TagCustomExample() {
  return (
    <Tag className="h-7 rounded-full border-transparent bg-background-accent-purple-bolder-hover px-3 text-text-contrary">
      Campaign
    </Tag>
  );
}
```

## Anatomy

```text
Tag
Tag.Root
Tag.Icon
Tag.Label
Tag.Remove
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| children | ReactNode | — | Visible content. Tag wraps it in Tag.Label and adds Tag.Remove when onRemove is supplied; Tag.Root renders compound parts directly. |
| label | string | — | Text used to name the remove button, not a rendered label. Tag infers it from plain-text children; set it for rich content or Tag.Root. |
| className | string | — | Custom styling and instance overrides. Appearance and color props are optional. |
| appearance | default \| rounded | default | Compact, slightly rounded corners or a taller pill shape. |
| color | neutral \| blue \| blue-light \| red \| red-light \| yellow \| yellow-light \| green \| green-light \| teal \| teal-light \| purple \| purple-light \| gray \| gray-light \| lime \| lime-light \| orange \| orange-light \| magenta \| magenta-light | neutral | Accent or neutral fill matching the design system Tag palette. |
| variant | default \| neutral \| outline | — | Deprecated. Prefer `color` and `appearance`. `outline` keeps a bordered tag. |
| onRemove | () => void | — | Called on removal. Tag automatically adds a remove button; Tag.Root requires an explicit Tag.Remove. The parent owns the item list. |
| removeLabel | string | — | Overrides the remove button's accessible name. |
| disabled | boolean | false | Dims the tag, exposes aria-disabled, and disables its remove button. |
| Tag.Remove.label / aria-label | string | — | Overrides the individual remove button's accessible name. aria-label takes precedence over label, then the root removeLabel. |
| native props | React.HTMLAttributes<HTMLSpanElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

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

## Accessibility

Static tags render as non-interactive spans. A removable tag contains a native button whose default name is “Remove” followed by the tag label; it supports normal keyboard activation. `Tag.Remove` also accepts a local `label` or `aria-label` to override that name.

Disabled tags expose `aria-disabled`, and their remove buttons are natively disabled. Do not make the entire tag clickable when only removal is intended. When removing an item, manage focus in the owning list or field so keyboard users can continue from a meaningful position.

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