<!-- index: /slotted/llms.txt -->
# tag

`data-ui="tag"` · Label for a category, removable or selectable.

## Minimal example

Example

```tsx
import { Tag, TagGroup } from '@slotted/react/tag';

export default function TagBasic() {
  return (
    <TagGroup aria-label="Labels on order SO-10482" role="list">
      <Tag>Wholesale</Tag>
      <Tag>Fragile</Tag>
      <Tag>Priority shipping</Tag>
    </TagGroup>
  );
}
```

## Props

### tag

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | Tag | Which of the six semantic colors the tag speaks in |
| `variant` | `'solid' \| 'soft' \| 'outline' \| 'dashed'` | soft | Tag | How that color is painted: filled, tinted, an edge alone, or that edge in dashes. A selected tag fills whatever its variant |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Tag | Type, glyph and gap come from the control scale, so a tag shrinks with density beside the controls it sits with |
| `shape` | `'pill' \| 'square'` | pill | Tag | A rounded chip, or a rectangle with the small corner radius |
| `inline` | `boolean` | false | Tag | No taller than the line of text around it, for a title or a sentence: the line keeps its height and what is under it its distance. The tag takes its own size where the line has the room and one line of the text where it does not; its words are at most nine tenths of the text around it. |
| `start` | `ReactNode` | — | Tag | A glyph or an avatar before the words, wrapped in the start part, which sizes and centers it |
| `end` | `ReactNode` | — | Tag | A glyph after the words, wrapped in the end part |
| `disabled` | `boolean` | false | Tag | Refuses every interaction the tag offers, including its removal |
| `onRemove` | `(request: TagRemoveRequest) => void` | — | Tag | Asks to be removed. The remove control is rendered only when this is present. request.reason is remove for the control and keyboard for Backspace or Delete; request.cancel() refuses it, and the group then leaves focus where it is |
| `messages` | `Partial<TagMessages>` | — | Tag | Overrides for the strings of the language in force, by key: remove is the word the remove control announces before the tag’s own label, so it reads “Remove Design” |
| `removeDisabled` | `boolean` | false | Tag | Refuses the removal while the rest of the tag stays operable |
| `orientation` | `'horizontal' \| 'vertical'` | horizontal | TagGroup | Which way the run reads. vertical also writes aria-orientation |
| `loop` | `boolean` | true | TagGroup | Whether the arrow keys wrap past the ends of the run |
| `role` | `string` | toolbar | TagGroup | toolbar makes the run one tab stop with arrow navigation inside it. Writing list turns that off and gives every chip role="listitem" |
| `render` | `(props) => ReactNode` | — | every member | Renders the member’s own element into another one — an li for a tag in a list, a router’s link component for a destination |
| `rootProps` | `ComponentProps<'span'>` | — | TagButton, TagLink, TagToggle | Reaches the chip box, which an interactive member’s own props do not land on |
| `ref` | `Ref<HTMLElement>` | — | every member | Reaches the element the member is: the chip box for Tag, the control for the other three |
| `TagDefaultsProvider` | `{ tone, variant, size, shape }` | — | a subtree | Sets the defaults once for every tag under it; an explicit prop still wins |

### tagButton

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | TagButton | Which of the six semantic colors the tag speaks in |
| `variant` | `'solid' \| 'soft' \| 'outline' \| 'dashed'` | soft | TagButton | How that color is painted: filled, tinted, an edge alone, or that edge in dashes. A selected tag fills whatever its variant |
| `size` | `'sm' \| 'md' \| 'lg'` | md | TagButton | Type, glyph and gap come from the control scale, so a tag shrinks with density beside the controls it sits with |
| `shape` | `'pill' \| 'square'` | pill | TagButton | A rounded chip, or a rectangle with the small corner radius |
| `start` | `ReactNode` | — | TagButton | A glyph or an avatar before the words, wrapped in the start part, which sizes and centers it |
| `end` | `ReactNode` | — | TagButton | A glyph after the words, wrapped in the end part |
| `disabled` | `boolean` | false | TagButton | Refuses every interaction the tag offers, including its removal |
| `onRemove` | `(request: TagRemoveRequest) => void` | — | TagButton | Asks to be removed. The remove control is rendered only when this is present. request.reason is remove for the control and keyboard for Backspace or Delete; request.cancel() refuses it, and the group then leaves focus where it is |
| `messages` | `Partial<TagMessages>` | — | TagButton | Overrides for the strings of the language in force, by key: remove is the word the remove control announces before the tag’s own label, so it reads “Remove Design” |
| `removeDisabled` | `boolean` | false | TagButton | Refuses the removal while the rest of the tag stays operable |
| `onClick` | `(event) => void` | — | TagButton | The command. It lands on the button the chip’s body is, so type, form and every native button prop reach the element that owns them |

### tagLink

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | TagLink | Which of the six semantic colors the tag speaks in |
| `variant` | `'solid' \| 'soft' \| 'outline' \| 'dashed'` | soft | TagLink | How that color is painted: filled, tinted, an edge alone, or that edge in dashes. A selected tag fills whatever its variant |
| `size` | `'sm' \| 'md' \| 'lg'` | md | TagLink | Type, glyph and gap come from the control scale, so a tag shrinks with density beside the controls it sits with |
| `shape` | `'pill' \| 'square'` | pill | TagLink | A rounded chip, or a rectangle with the small corner radius |
| `start` | `ReactNode` | — | TagLink | A glyph or an avatar before the words, wrapped in the start part, which sizes and centers it |
| `end` | `ReactNode` | — | TagLink | A glyph after the words, wrapped in the end part |
| `disabled` | `boolean` | false | TagLink | Refuses every interaction the tag offers, including its removal |
| `onRemove` | `(request: TagRemoveRequest) => void` | — | TagLink | Asks to be removed. The remove control is rendered only when this is present. request.reason is remove for the control and keyboard for Backspace or Delete; request.cancel() refuses it, and the group then leaves focus where it is |
| `messages` | `Partial<TagMessages>` | — | TagLink | Overrides for the strings of the language in force, by key: remove is the word the remove control announces before the tag’s own label, so it reads “Remove Design” |
| `removeDisabled` | `boolean` | false | TagLink | Refuses the removal while the rest of the tag stays operable |
| `href` | `string` | — | TagLink | The destination. A disabled TagLink loses it and announces aria-disabled, because an anchor without a destination is not a link |

### tagToggle

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | TagToggle | Which of the six semantic colors the tag speaks in |
| `variant` | `'solid' \| 'soft' \| 'outline' \| 'dashed'` | soft | TagToggle | How that color is painted: filled, tinted, an edge alone, or that edge in dashes. A selected tag fills whatever its variant |
| `size` | `'sm' \| 'md' \| 'lg'` | md | TagToggle | Type, glyph and gap come from the control scale, so a tag shrinks with density beside the controls it sits with |
| `shape` | `'pill' \| 'square'` | pill | TagToggle | A rounded chip, or a rectangle with the small corner radius |
| `start` | `ReactNode` | — | TagToggle | A glyph or an avatar before the words, wrapped in the start part, which sizes and centers it |
| `end` | `ReactNode` | — | TagToggle | A glyph after the words, wrapped in the end part |
| `disabled` | `boolean` | false | TagToggle | Refuses every interaction the tag offers, including its removal |
| `onRemove` | `(request: TagRemoveRequest) => void` | — | TagToggle | Asks to be removed. The remove control is rendered only when this is present. request.reason is remove for the control and keyboard for Backspace or Delete; request.cancel() refuses it, and the group then leaves focus where it is |
| `messages` | `Partial<TagMessages>` | — | TagToggle | Overrides for the strings of the language in force, by key: remove is the word the remove control announces before the tag’s own label, so it reads “Remove Design” |
| `removeDisabled` | `boolean` | false | TagToggle | Refuses the removal while the rest of the tag stays operable |
| `selected` | `boolean` | false | TagToggle | The selection the consumer owns. Passing it puts the tag in controlled mode for good |
| `defaultSelected` | `boolean` | — | TagToggle | The selection an uncontrolled tag starts from, read once. A later change to it is not silently adopted |
| `onSelectedChange` | `(selected, request) => void` | — | TagToggle | Asks for the opposite selection. request.reason is pointer or keyboard, and request.cancel() refuses it |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `tone` | `accent`, `secondary`, `info`, `success`, `warning`, `danger` | `secondary` |
| `variant` | `solid`, `soft`, `outline`, `dashed` | `soft` |
| `size` | `sm`, `md`, `lg` | `md` |
| `shape` | `pill`, `square` | `pill` |
| `orientation` | `horizontal`, `vertical` | `horizontal` |

## Rules

- The WAI-ARIA Authoring Practices define no tag or chip pattern. The group follows the Toolbar pattern, a chip that acts and the remove control follow the Button pattern, a chip that navigates follows the Link pattern, and a chip that holds a selection uses aria-pressed from WAI-ARIA 1.2.
- The chip box is never the interactive element. A button cannot contain a button and an anchor cannot contain either, so a chip that both acts and removes puts its two controls side by side: the body is the primary target and the remove control is its sibling.
- The remove control’s name is composed, not repeated: aria-labelledby joins a hidden word to the tag’s own label, so it announces “Remove Design” rather than “Remove”. Text referenced by aria-labelledby counts even when the element holding it is hidden.
- Backspace and Delete on any control inside a removable tag ask for the same removal the X does, and the request says which of the two it was.
- The focus ring is drawn on the control, never on the chip: a chip can hold two controls, and a ring around the whole box could not say which one has focus. The ring is inset, so it does not cover the remove control beside the body or touch the next tag in a wrapped run.
- The remove control is as tall as the chip and as wide as its glyph plus a step of air on each side, floored at the WCAG 2.2 2.5.8 minimum of 24 CSS pixels, which carries it past that minimum in both axes at every size and every density. The chip’s own height is floored at that minimum for the same reason.
- A tag is one line. A value too long for its container is clipped with an ellipsis rather than reflowed, and the clipping is visual only: text-overflow shortens nothing, so the whole value stays in the DOM, stays in the accessibility tree, and a page search still finds it.
- The label is a bidi isolate whose direction comes from its own first strong character, so an Arabic value inside an English page reads right to left and is clipped at its own end.
- Under forced colors every tone ground becomes one system color, so tag draws its edge in currentColor there, and a selected chip takes the system’s own Highlight pair — its whole signal is a ground the system has replaced.
- A static tag carries no role of its own. What a value means comes from where it sits, and a role invented here would be wrong more often than right.
- A group of static tags is written role="list", which announces its length and turns the arrow keys off — a list is a structure rather than a widget.
- The command is a real button, so Enter and Space both activate it and the platform supplies the rest.
- A disabled TagButton is natively disabled. Reach for aria-disabled through rootProps only when the chip has to stay in the tab sequence to explain itself.
- The destination is a real anchor, so middle click, the context menu, download and “open in new tab” all keep working.
- A chip that navigates to another origin says so in its own words or in a visually hidden sentence. The external marker belongs to the link family, on a link.
- A selected tag announces aria-pressed, not aria-selected. aria-selected is only valid inside a listbox, a grid or a tree, and an option may not contain the remove control that tag puts beside the label.
- The label never changes with the state, which is the APG’s rule for a toggle: “Open” stays “Open” and the state is announced beside it.
- Selection is not color alone. The chip fills, and a check grows into the label beside the words — WCAG 2.2 1.4.1.

## Tokens

`--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-inner-size`, `--slotted-control-inner-size-md`, `--slotted-control-inner-size-sm`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-weight-medium`, `--slotted-line-height-xs`, `--slotted-radius-full`, `--slotted-radius-sm`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-tag-border-color`, `--slotted-tag-border-width`, `--slotted-tag-font-family`, `--slotted-tag-font-weight`, `--slotted-tag-group-gap`, `--slotted-tag-inset-block`, `--slotted-tag-inset-inline`, `--slotted-tag-state-layer-active`, `--slotted-tag-state-layer-hover`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text-box-edge`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-solid-active`, `--slotted-tone-accent-solid-hover`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-on-solid`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-solid-active`, `--slotted-tone-danger-solid-hover`, `--slotted-tone-danger-subtle-active`, `--slotted-tone-danger-subtle-hover`, `--slotted-tone-danger-surface`, `--slotted-tone-danger-text`, `--slotted-tone-info-border`, `--slotted-tone-info-on-solid`, `--slotted-tone-info-solid`, `--slotted-tone-info-solid-active`, `--slotted-tone-info-solid-hover`, `--slotted-tone-info-subtle-active`, `--slotted-tone-info-subtle-hover`, `--slotted-tone-info-surface`, `--slotted-tone-info-text`, `--slotted-tone-secondary-border`, `--slotted-tone-secondary-on-solid`, `--slotted-tone-secondary-solid-active`, `--slotted-tone-secondary-solid-hover`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-tone-secondary-surface`, `--slotted-tone-secondary-text`, `--slotted-tone-success-border`, `--slotted-tone-success-on-solid`, `--slotted-tone-success-solid`, `--slotted-tone-success-solid-active`, `--slotted-tone-success-solid-hover`, `--slotted-tone-success-subtle-active`, `--slotted-tone-success-subtle-hover`, `--slotted-tone-success-surface`, `--slotted-tone-success-text`, `--slotted-tone-warning-border`, `--slotted-tone-warning-on-solid`, `--slotted-tone-warning-solid`, `--slotted-tone-warning-solid-active`, `--slotted-tone-warning-solid-hover`, `--slotted-tone-warning-subtle-active`, `--slotted-tone-warning-subtle-hover`, `--slotted-tone-warning-surface`, `--slotted-tone-warning-text`

## Examples

See [tag.examples.md](./tag.examples.md).
