# Tag

A small label attached to something: a category, an environment, a file.

A small bordered label attached to something: a category, an environment, an attachment. The squarer, bordered label of tables and fields (a category, an attachment, a value in a tags input) in neutral, accent or one of the eight tag hues, with an optional remove button. One line, never wraps or shrinks. Sizes md (24px) and sm (22px); rounded by default, pill in a pill-shaped host.

Kind: component · Category: Display · Status: stable · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add tag
```

It writes the folder `tag/` into the project's ui folder (`index.ts`, `tag.tsx`, `Tag.vue`, `Tag.svelte`, `tag.recipe.ts`), and what it is built from: [Button](/components/button.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Tag } from "@/components/ui/tag";
```

```vue
import { Tag } from "@/components/ui/tag";
```

```svelte
import { Tag } from "$lib/components/ui/tag";
```

## Parts

In the DOM the root carries `data-slot="tag"` and each part `data-slot="tag-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `span` | `tag` |  |  |
| `dot` | `span` | `tag-dot` | optional | 6px dot in the tag's hue; aria-hidden. Only when dot is set. |
| `icon` | `span` | `tag-icon` | optional | A glyph before the label (12px, 11px at sm) in the tag's colour, aria-hidden; takes the dot's place (an attachment's file glyph). |
| `label` | `span` | `tag-label` | optional | Text of the tag; truncates at the end when the tag has less room than its text, and then carries its full text as a title. |
| `remove` | `button` | `tag-remove` | optional | The real Button (ghost, xs, square), marked data-tag="remove", with an x icon and an aria-label; its shape follows the tag's (round on a pill, rounded on a rounded tag). The tag grows to 26px to hold it (the button is 20px at sm, and the tag stays 22px). Under a coarse pointer its hit area reaches 36px (a transparent ::after); the tag does not grow. With removeTooltip it sits inside the real Tooltip. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"neutral" \| "accent" \| "blue" \| "green" \| "orange" \| "red" \| "purple" \| "cyan" \| "yellow" \| "pink"` | `"neutral"` | neutral (ink-3), accent and the eight tag hues (from --fndn-tag-*). The fill is 14% of the hue on the surface, the 1px border 30%, the text the hue mixed with ink; dark: a richer fill (26%), border (34%) and lighter text. |
| `variant` | `"tint" \| "outline"` | `"tint"` | tint: the box takes the hue (fill 14%, border 30%, text mixed with ink). outline (Linear's labels): a neutral box (no fill, the strong hairline, ink-2 text) with the hue only in its dot, which shows without `dot` (an icon still takes its place): for many labels of many hues in a row, an issue's labels, a filter. |
| `size` | `"md" \| "sm"` | `"md"` | md 24px / 13px; sm 22px / 11.5px. |
| `shape` | `"rounded" \| "pill"` | `"rounded"` | Radius only: rounded is radius.control (radius.chip at sm); pill for a tag in a pill-shaped host (a prompt-bar attachment). |
| `dot` | `boolean` | `false` | Render the leading dot part in the tag's hue. Always shown in the outline variant. |
| `removable` | `boolean` | `false` | Render the remove button at the end. |
| `removeLabel` | `string` | `"Remove"` | aria-label of the remove button, e.g. "Remove invoice.pdf". |
| `removeTooltip` | `string` |  | A tooltip on the remove button (the real Tooltip around it), e.g. "Remove". None by default. |
| `removeProps` | `object` |  | Attributes for the remove button (React and Svelte: spread on it; Vue: v-bind), e.g. a data attribute the owner uses to move focus after a removal, or an engine's delete-trigger props. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `remove` | the remove button was clicked (React onRemove, Vue @remove, Svelte onremove) |

## Slots

| Slot | Content |
| --- | --- |
| `default` | Label |
| `icon` | A glyph before the label (React: icon node; Vue: #icon slot; Svelte: icon snippet). Replaces the dot. |

## Keyboard and accessibility

Notes:

- The dot and the icon are aria-hidden; the label carries the meaning. Tone alone never does.
- The remove button needs an aria-label that names the tag (removeLabel), and focus must go somewhere sensible after removal (the owner of the list decides).

## Motion

- remove button: the button's press scale; hover and press tint the tag's own colour at duration.fast, ease
- no other motion

## Tokens

`color.surface`, `color.ink`, `color.ink-3`, `color.accent`, `color.tag-blue`, `color.tag-green`, `color.tag-orange`, `color.tag-red`, `color.tag-purple`, `color.tag-cyan`, `color.tag-yellow`, `color.tag-pink`, `radius.pill`, `radius.control`, `radius.chip`, `text.sm`, `color.line-strong`, `color.ink-2`

## Dependencies

- [Button](/components/button.md)
- [Tooltip](/components/tooltip.md)

## Examples

### Labels on an issue

React · `issue-labels.tsx`

```tsx
import { Tag } from "@/components/ui/tag";

const labels = [
  { name: "bug", tone: "red" },
  { name: "billing-api", tone: "blue" },
  { name: "priority: high", tone: "orange" },
] as const;

/* an issue's labels, Linear's way: neutral boxes, the hue only in the dot, so a row of many hues stays quiet */
export default function IssueLabels() {
  return (
    <div className="flex w-80 flex-col gap-2 text-sm">
      <div>
        <p className="font-medium text-ink">Webhook retries stop after the third attempt</p>
        <p className="text-ink-2">#491 opened by Priya Raman · 3 h ago</p>
      </div>
      <div className="flex flex-wrap gap-1.5">
        {labels.map((label) => (
          <Tag key={label.name} tone={label.tone} variant="outline">{label.name}</Tag>
        ))}
      </div>
    </div>
  );
}
```

Vue · `issue-labels.vue`

```vue
<script setup lang="ts">
import { Tag } from "@/components/ui/tag";

const labels = [
  { name: "bug", tone: "red" },
  { name: "billing-api", tone: "blue" },
  { name: "priority: high", tone: "orange" },
] as const;
</script>

<!-- an issue's labels, Linear's way: neutral boxes, the hue only in the dot, so a row of many hues stays quiet -->
<template>
  <div class="flex w-80 flex-col gap-2 text-sm">
    <div>
      <p class="font-medium text-ink">Webhook retries stop after the third attempt</p>
      <p class="text-ink-2">#491 opened by Priya Raman · 3 h ago</p>
    </div>
    <div class="flex flex-wrap gap-1.5">
      <Tag v-for="label in labels" :key="label.name" :tone="label.tone" variant="outline">{{ label.name }}</Tag>
    </div>
  </div>
</template>
```

Svelte · `issue-labels.svelte`

```svelte
<script lang="ts">
  import { Tag } from "$lib/components/ui/tag";

  const labels = [
    { name: "bug", tone: "red" },
    { name: "billing-api", tone: "blue" },
    { name: "priority: high", tone: "orange" },
  ] as const;
</script>

<!-- an issue's labels, Linear's way: neutral boxes, the hue only in the dot, so a row of many hues stays quiet -->
<div class="flex w-80 flex-col gap-2 text-sm">
  <div>
    <p class="font-medium text-ink">Webhook retries stop after the third attempt</p>
    <p class="text-ink-2">#491 opened by Priya Raman · 3 h ago</p>
  </div>
  <div class="flex flex-wrap gap-1.5">
    {#each labels as label (label.name)}
      <Tag tone={label.tone} variant="outline">{label.name}</Tag>
    {/each}
  </div>
</div>
```

### Labels in a pull request table

React · `pull-requests-table.tsx`

```tsx
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tag } from "@/components/ui/tag";

const pulls = [
  { id: "#482", title: "Add retry to webhook delivery", labels: [{ name: "backend", tone: "blue" }, { name: "needs review", tone: "yellow" }] },
  { id: "#479", title: "Update pricing page copy", labels: [{ name: "docs", tone: "cyan" }] },
  { id: "#476", title: "Fix flaky upload test", labels: [{ name: "tests", tone: "purple" }] },
] as const;

/* sm tags in a dense table */
export default function PullRequestsTable() {
  return (
    <Table aria-label="Open pull requests" className="w-[440px] max-w-full">
      <TableHeader>
        <TableRow>
          <TableHead>Pull request</TableHead>
          <TableHead>Labels</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {pulls.map((pull) => (
          <TableRow key={pull.id}>
            <TableCell>{pull.id} {pull.title}</TableCell>
            <TableCell>
              <div className="flex flex-wrap gap-1">
                {pull.labels.map((label) => (
                  <Tag key={label.name} tone={label.tone} size="sm">{label.name}</Tag>
                ))}
              </div>
            </TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  );
}
```

Vue · `pull-requests-table.vue`

```vue
<script setup lang="ts">
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tag } from "@/components/ui/tag";

const pulls = [
  { id: "#482", title: "Add retry to webhook delivery", labels: [{ name: "backend", tone: "blue" }, { name: "needs review", tone: "yellow" }] },
  { id: "#479", title: "Update pricing page copy", labels: [{ name: "docs", tone: "cyan" }] },
  { id: "#476", title: "Fix flaky upload test", labels: [{ name: "tests", tone: "purple" }] },
] as const;
</script>

<!-- sm tags in a dense table -->
<template>
  <Table aria-label="Open pull requests" class="w-[440px] max-w-full">
    <TableHeader>
      <TableRow>
        <TableHead>Pull request</TableHead>
        <TableHead>Labels</TableHead>
      </TableRow>
    </TableHeader>
    <TableBody>
      <TableRow v-for="pull in pulls" :key="pull.id">
        <TableCell>{{ pull.id }} {{ pull.title }}</TableCell>
        <TableCell>
          <div class="flex flex-wrap gap-1">
            <Tag v-for="label in pull.labels" :key="label.name" :tone="label.tone" size="sm">{{ label.name }}</Tag>
          </div>
        </TableCell>
      </TableRow>
    </TableBody>
  </Table>
</template>
```

Svelte · `pull-requests-table.svelte`

```svelte
<script lang="ts">
  import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "$lib/components/ui/table";
  import { Tag } from "$lib/components/ui/tag";

  const pulls = [
    { id: "#482", title: "Add retry to webhook delivery", labels: [{ name: "backend", tone: "blue" }, { name: "needs review", tone: "yellow" }] },
    { id: "#479", title: "Update pricing page copy", labels: [{ name: "docs", tone: "cyan" }] },
    { id: "#476", title: "Fix flaky upload test", labels: [{ name: "tests", tone: "purple" }] },
  ] as const;
</script>

<!-- sm tags in a dense table -->
<Table aria-label="Open pull requests" class="w-[440px] max-w-full">
  <TableHeader>
    <TableRow>
      <TableHead>Pull request</TableHead>
      <TableHead>Labels</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    {#each pulls as pull (pull.id)}
      <TableRow>
        <TableCell>{pull.id} {pull.title}</TableCell>
        <TableCell>
          <div class="flex flex-wrap gap-1">
            {#each pull.labels as label (label.name)}
              <Tag tone={label.tone} size="sm">{label.name}</Tag>
            {/each}
          </div>
        </TableCell>
      </TableRow>
    {/each}
  </TableBody>
</Table>
```

### Applied filters

React · `applied-filters.tsx`

```tsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Tag } from "@/components/ui/tag";

const initial = ["Status: Failed", "Branch: main", "Project: billing-api"];

export default function AppliedFilters() {
  const [filters, setFilters] = useState(initial);
  return (
    <div className="flex w-80 flex-wrap items-center gap-1.5 text-sm">
      {filters.map((filter) => (
        <Tag key={filter} removable removeLabel={`Remove ${filter}`} onRemove={() => setFilters(filters.filter((f) => f !== filter))}>
          {filter}
        </Tag>
      ))}
      {filters.length ? (
        <Button size="xs" variant="ghost" onClick={() => setFilters([])}>Clear all</Button>
      ) : (
        <Button size="xs" variant="ghost" onClick={() => setFilters(initial)}>Restore filters</Button>
      )}
    </div>
  );
}
```

Vue · `applied-filters.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Tag } from "@/components/ui/tag";

const initial = ["Status: Failed", "Branch: main", "Project: billing-api"];
const filters = ref(initial);
</script>

<template>
  <div class="flex w-80 flex-wrap items-center gap-1.5 text-sm">
    <Tag v-for="filter in filters" :key="filter" removable :removeLabel="`Remove ${filter}`" @remove="filters = filters.filter((f) => f !== filter)">
      {{ filter }}
    </Tag>
    <Button v-if="filters.length" size="xs" variant="ghost" @click="filters = []">Clear all</Button>
    <Button v-else size="xs" variant="ghost" @click="filters = initial">Restore filters</Button>
  </div>
</template>
```

Svelte · `applied-filters.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Tag } from "$lib/components/ui/tag";

  const initial = ["Status: Failed", "Branch: main", "Project: billing-api"];
  let filters = $state(initial);
</script>

<div class="flex w-80 flex-wrap items-center gap-1.5 text-sm">
  {#each filters as filter (filter)}
    <Tag removable removeLabel={`Remove ${filter}`} onremove={() => (filters = filters.filter((f) => f !== filter))}>
      {filter}
    </Tag>
  {/each}
  {#if filters.length}
    <Button size="xs" variant="ghost" onclick={() => (filters = [])}>Clear all</Button>
  {:else}
    <Button size="xs" variant="ghost" onclick={() => (filters = initial)}>Restore filters</Button>
  {/if}
</div>
```

### Attachments on a comment

React · `attachments.tsx`

```tsx
import { useState } from "react";
import { Tag } from "@/components/ui/tag";

/* pill tags in a pill-shaped host (a comment box), with a tooltip on the remove button */
export default function Attachments() {
  const [files, setFiles] = useState(["deploy-log.txt", "checkout-error.png"]);
  return (
    <div className="flex flex-wrap gap-1.5">
      {files.map((file) => (
        <Tag key={file} shape="pill" removable removeLabel={`Remove ${file}`} removeTooltip="Remove" onRemove={() => setFiles(files.filter((f) => f !== file))}>
          {file}
        </Tag>
      ))}
    </div>
  );
}
```

Vue · `attachments.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Tag } from "@/components/ui/tag";

const files = ref(["deploy-log.txt", "checkout-error.png"]);
</script>

<!-- pill tags in a pill-shaped host (a comment box), with a tooltip on the remove button -->
<template>
  <div class="flex flex-wrap gap-1.5">
    <Tag v-for="file in files" :key="file" shape="pill" removable :removeLabel="`Remove ${file}`" removeTooltip="Remove" @remove="files = files.filter((f) => f !== file)">
      {{ file }}
    </Tag>
  </div>
</template>
```

Svelte · `attachments.svelte`

```svelte
<script lang="ts">
  import { Tag } from "$lib/components/ui/tag";

  let files = $state(["deploy-log.txt", "checkout-error.png"]);
</script>

<!-- pill tags in a pill-shaped host (a comment box), with a tooltip on the remove button -->
<div class="flex flex-wrap gap-1.5">
  {#each files as file (file)}
    <Tag shape="pill" removable removeLabel={`Remove ${file}`} removeTooltip="Remove" onremove={() => (files = files.filter((f) => f !== file))}>
      {file}
    </Tag>
  {/each}
</div>
```

### Label list with open counts

React · `label-list.tsx`

```tsx
import { Count } from "@/components/ui/count";
import { Tag } from "@/components/ui/tag";

const labels = [
  { name: "bug", tone: "red", open: 14 },
  { name: "feature", tone: "green", open: 32 },
  { name: "docs", tone: "blue", open: 6 },
] as const;

/* a dot carries the hue where the label stands on its own */
export default function LabelList() {
  return (
    <ul className="flex w-48 flex-col gap-1.5 text-sm">
      {labels.map((label) => (
        <li key={label.name} className="flex items-center justify-between gap-3">
          <Tag tone={label.tone} dot>{label.name}</Tag>
          <Count>{label.open}</Count>
        </li>
      ))}
    </ul>
  );
}
```

Vue · `label-list.vue`

```vue
<script setup lang="ts">
import { Count } from "@/components/ui/count";
import { Tag } from "@/components/ui/tag";

const labels = [
  { name: "bug", tone: "red", open: 14 },
  { name: "feature", tone: "green", open: 32 },
  { name: "docs", tone: "blue", open: 6 },
] as const;
</script>

<!-- a dot carries the hue where the label stands on its own -->
<template>
  <ul class="flex w-48 flex-col gap-1.5 text-sm">
    <li v-for="label in labels" :key="label.name" class="flex items-center justify-between gap-3">
      <Tag :tone="label.tone" dot>{{ label.name }}</Tag>
      <Count>{{ label.open }}</Count>
    </li>
  </ul>
</template>
```

Svelte · `label-list.svelte`

```svelte
<script lang="ts">
  import { Count } from "$lib/components/ui/count";
  import { Tag } from "$lib/components/ui/tag";

  const labels = [
    { name: "bug", tone: "red", open: 14 },
    { name: "feature", tone: "green", open: 32 },
    { name: "docs", tone: "blue", open: 6 },
  ] as const;
</script>

<!-- a dot carries the hue where the label stands on its own -->
<ul class="flex w-48 flex-col gap-1.5 text-sm">
  {#each labels as label (label.name)}
    <li class="flex items-center justify-between gap-3">
      <Tag tone={label.tone} dot>{label.name}</Tag>
      <Count>{label.open}</Count>
    </li>
  {/each}
</ul>
```

## Recipe

`tag.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* tag — the squarer, bordered label of tables and fields, in neutral, accent or one of the eight
 * tag hues; optionally removable. Never wraps, never shrinks. Sizes: md 24px (default) · sm 22px.
 * Shape: rounded (radius.control, radius.chip at sm) by default, pill in a pill-shaped host.
 *
 * Every tone sets --_hue only: the fill (14%), the 1px border (30%) and the text (62% with ink)
 * all mix from it; dark: a richer fill and border and lighter text. The dot takes the hue.
 * An icon part may stand before the label (an attachment's file glyph); it takes the dot's place.
 * variant outline (Linear's labels): the hue is only the dot; the box is neutral (no fill, the
 * strong hairline, ink-2 text), so many labels of many hues sit quietly in a row. The adapters
 * show the dot in this look (unless an icon takes its place).
 * Variant order matters: tone < variant < size < shape < removable (a later key wins).
 * The remove button is the real Button, marked data-tag="remove"; its restyling is the `remove`
 * slot below, passed as className, and its shape follows the tag's. */

export const tag = tv({
  slots: {
    base: [
      "[--_hue:var(--fndn-ink-3)]",
      "inline-flex shrink-0 items-center gap-[5px] max-w-full h-6 px-[7px] rounded-control",
      "border border-solid border-[color:color-mix(in_srgb,var(--_hue)_30%,var(--fndn-surface))]",
      "text-sm font-normal leading-none whitespace-nowrap",
      "bg-[color:color-mix(in_srgb,var(--_hue)_14%,var(--fndn-surface))] text-[color:color-mix(in_oklch,var(--_hue)_62%,var(--fndn-ink))]",
      "[:is(.dark,[data-theme=dark])_&]:text-[color:color-mix(in_srgb,var(--_hue)_70%,var(--fndn-ink))]",
      "[:is(.dark,[data-theme=dark])_&]:bg-[color:color-mix(in_srgb,var(--_hue)_26%,var(--fndn-surface))]",
      "[:is(.dark,[data-theme=dark])_&]:border-[color:color-mix(in_srgb,var(--_hue)_34%,var(--fndn-surface))]",
    ],
    /* a tag longer than the room truncates at the end of its own text; the 2px block padding,
     * taken back by the margin, keeps descenders out of the clip */
    label: "min-w-0 -my-0.5 py-0.5 overflow-hidden text-ellipsis [unicode-bidi:plaintext]",
    dot: "shrink-0 size-1.5 rounded-[50%] bg-[color:var(--_hue)]",
    icon: "inline-flex shrink-0 text-[12px] [&>[data-slot=icon]]:size-[1em] [&>svg]:size-[1em]",
    /* on the Button: tints of the tag's own colour, so they read on every hue. Under a finger
     * the hit area reaches 36px (32px at sm); the tag does not grow. */
    remove: [
      "-ms-0.5 text-inherit",
      "hover:bg-[color:color-mix(in_srgb,currentColor_12%,transparent)] active:bg-[color:color-mix(in_srgb,currentColor_22%,transparent)]",
      "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-1.5 pointer-coarse:after:content-['']",
    ],
  },
  variants: {
    tone: {
      neutral: {},
      accent: { base: "[--_hue:var(--fndn-accent)]" },
      blue: { base: "[--_hue:var(--fndn-tag-blue)]" },
      green: { base: "[--_hue:var(--fndn-tag-green)]" },
      orange: { base: "[--_hue:var(--fndn-tag-orange)]" },
      red: { base: "[--_hue:var(--fndn-tag-red)]" },
      purple: { base: "[--_hue:var(--fndn-tag-purple)]" },
      cyan: { base: "[--_hue:var(--fndn-tag-cyan)]" },
      yellow: { base: "[--_hue:var(--fndn-tag-yellow)]" },
      pink: { base: "[--_hue:var(--fndn-tag-pink)]" },
    },
    /* tint (default): the box takes the hue. outline: a neutral box, the hue only in the dot */
    variant: {
      tint: {},
      outline: {
        base: [
          "bg-transparent border-line-strong text-ink-2",
          "[:is(.dark,[data-theme=dark])_&]:bg-transparent [:is(.dark,[data-theme=dark])_&]:border-line-strong [:is(.dark,[data-theme=dark])_&]:text-ink-2",
        ],
      },
    },
    /* sm — 22px, for table cells and dense rows */
    size: {
      md: {},
      sm: {
        base: "h-[22px] px-1.5 text-[11.5px]",
        icon: "text-[11px]",
        remove: "size-5 min-h-5 pointer-coarse:after:-inset-2",
      },
    },
    /* radius only */
    shape: {
      rounded: {},
      pill: { base: "rounded-pill" },
    },
    /* the tag grows to 26px to hold the 24px button inside its 1px border; at sm it stays 22px */
    removable: { true: { base: "h-[26px] pe-0" } },
  },
  compoundVariants: [
    { shape: "rounded", size: "sm", class: { base: "rounded-chip" } },
    { removable: true, size: "sm", class: { base: "h-[22px]" } },
  ],
  defaultVariants: { tone: "neutral", variant: "tint", size: "md", shape: "rounded" },
});

export type TagRecipeProps = VariantProps<typeof tag>;
```
