# Tag

> A value chip in three variants and two sizes that can be removed, shrinking and fading out before your list drops it.

Source: https://docs.cherry.al/components/tag

> For the complete documentation index, see [llms.txt](https://docs.cherry.al/llms.txt).

# Tag

<Preview bleed>
<iframe className="light-only" src="https://v2.cherry.al/preview/tag?theme=light" title="Tag preview" loading="lazy" style={{ width: "100%", height: "420px" }} />
<iframe className="dark-only" src="https://v2.cherry.al/preview/tag?theme=dark" title="Tag preview" loading="lazy" style={{ width: "100%", height: "420px" }} />

```tsx
import { Tag } from "@cherry-design-system/react";

export function Topic() {
  return <Tag>React</Tag>;
}
```
</Preview>

A Tag shows a value, such as a selected filter or a topic, and can be removable. Removal shrinks and fades the chip out. For a read-only status label, use [Badge](/components/badge).

## Examples

### Variants and sizes

```tsx
import { Tag } from "@cherry-design-system/react";

export function Variants() {
  return (
    <>
      <Tag variant="neutral">Neutral</Tag>
      <Tag variant="accent">Accent</Tag>
      <Tag variant="outline">Outline</Tag>
      <Tag size="sm">Small</Tag>
    </>
  );
}
```

### Removable list

Passing `onRemove` shows the remove button. It is called once the exit animation has finished, so drop the tag from your state there.

```tsx
"use client";

import { useState } from "react";
import { Tag } from "@cherry-design-system/react";

export function Filters() {
  const [tags, setTags] = useState(["React", "TypeScript", "CSS"]);

  return (
    <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
      {tags.map((tag) => (
        <Tag
          key={tag}
          variant="outline"
          onRemove={() => setTags((current) => current.filter((t) => t !== tag))}
        >
          {tag}
        </Tag>
      ))}
    </div>
  );
}
```

### Disabled

`disabled` disables the remove button.

```tsx
import { Tag } from "@cherry-design-system/react";

export function Locked() {
  return (
    <Tag disabled onRemove={() => {}}>
      Required
    </Tag>
  );
}
```

## Properties

<Field value="variant" type='"neutral" | "accent" | "outline"'>
  Visual style. Defaults to `"neutral"`.
</Field>

<Field value="size" type='"sm" | "md"'>
  Chip size. Defaults to `"md"`.
</Field>

<Field value="onRemove" type="() => void">
  Shows the remove button. Called once the exit animation has finished: drop the tag from your list there.
</Field>

<Field value="removeLabel" type="string">
  Remove button name, followed by the tag text. Defaults to `"Remove"`.
</Field>

<Field value="disabled" type="boolean">
  Disables the remove button.
</Field>

Tag renders a `<span>`, forwards its ref to it and passes every other `<span>` attribute through. It is a client component.

## Styling

| Hook | Values |
| --- | --- |
| `.cherry-tag` | Root element |
| `data-variant` | `neutral`, `outline`, `accent` |
| `data-size` | `sm`, `md` |
| `data-exiting` | Present during the remove animation |
| Parts | `.cherry-tag__label`, `.cherry-tag__remove` |

`neutral` reads `--cherry-bg-muted`, `accent` reads `--cherry-accent-subtle` and `--cherry-accent-fg`, and `outline` reads `--cherry-border-default`.

## Accessibility

- The remove button is named by `removeLabel` plus the tag text, for example "Remove React". Translate it with `removeLabel`.
- With the remove button focused, Backspace or Delete removes the tag.
- Don't rely on color alone to carry meaning.

<Button href="https://github.com/cherry-design-system/react/tree/main/src/components/tag" icon="code" iconPosition="left">
  View Source
</Button>
