Skip to content
All components
Primitives

Tag

Show a compact label for a filter, topic, person or attribute, optionally with a dot, avatar, icon or count, and optionally selectable or removable.

A compact label with an optional dot, avatar, count, checkbox or remove button.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add tag

Then import it from @/components/ui/tag. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Removable

Remove filters with labelled close buttons. TagClose takes its name from TagLabel; the consumer removes the tag and decides where focus goes next. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Tag, TagClose, TagLabel } from "@/components/ui/tag"

const initialFilters = ["Design", "Research", "Engineering", "Marketing"]

export function TagRemovable() {
  const [filters, setFilters] = React.useState(initialFilters)
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <div className="flex flex-col gap-2">
        <p id="tag-demo-filters" className="text-label-sm text-strong-950">
          Active filters
        </p>
        {filters.length ? (
          <ul aria-labelledby="tag-demo-filters" className="flex flex-wrap items-center gap-2">
            {filters.map((filter) => (
              <li key={filter}>
                <Tag>
                  <TagLabel>{filter}</TagLabel>
                  <TagClose onClick={() => setFilters((current) => current.filter((item) => item !== filter))} />
                </Tag>
              </li>
            ))}
          </ul>
        ) : (
          <p className="text-paragraph-sm text-sub-600">No filters applied.</p>
        )}
      </div>
    </div>
  )
}

Sizes

Compare the small, medium and large tag sizes. Built-in actions keep a 24 by 24 target at every size. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Tag, TagLabel } from "@/components/ui/tag"

export function TagSizes() {
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <div className="flex flex-wrap items-center gap-2">
        <Tag size="sm">
          <TagLabel>Small</TagLabel>
        </Tag>
        <Tag size="md">
          <TagLabel>Medium</TagLabel>
        </Tag>
        <Tag size="lg">
          <TagLabel>Large</TagLabel>
        </Tag>
      </div>
    </div>
  )
}

Leading content

Lead a tag with a status dot, an avatar, an icon or a count. The dot, avatar and icon are decorative; the label and visually hidden count text carry the meaning. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { GlobeIcon } from "lucide-react"

import {
  Tag,
  TagAvatar,
  TagCount,
  TagDot,
  TagLabel,
} from "@/components/ui/tag"

export function TagLeadingContent() {
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <div className="flex flex-wrap items-center gap-2">
        <Tag>
          <TagDot color="success" />
          <TagLabel>Active</TagLabel>
        </Tag>
        <Tag>
          <TagAvatar>OR</TagAvatar>
          <TagLabel>Olivia Rhye</TagLabel>
        </Tag>
        <Tag>
          <GlobeIcon aria-hidden="true" />
          <TagLabel>Public</TagLabel>
        </Tag>
        <Tag>
          <TagLabel>Inbox</TagLabel>
          <TagCount>
            24<span className="sr-only"> messages</span>
          </TagCount>
        </Tag>
      </div>
    </div>
  )
}

Selectable

Make tags selectable with a checkbox named by the label. A fieldset legend names the set; the parent owns which tags are checked. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import {
  Tag,
  TagCheckbox,
  TagCount,
  TagLabel,
} from "@/components/ui/tag"

const topics = [
  { label: "Accessibility", count: 12 },
  { label: "Tokens", count: 8 },
  { label: "Motion", count: 3 },
]

export function TagSelectable() {
  
  const [selected, setSelected] = React.useState<string[]>(["Accessibility"])

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <fieldset className="flex flex-col gap-2">
        <legend className="mb-2 text-label-sm text-strong-950">Topics</legend>
        <div className="flex flex-wrap items-center gap-2">
          {topics.map((topic) => (
            <Tag key={topic.label} size="lg">
              <TagCheckbox
                checked={selected.includes(topic.label)}
                onCheckedChange={(checked) =>
                  setSelected((current) => (checked === true ? [...current, topic.label] : current.filter((item) => item !== topic.label)))
                }
              />
              <TagLabel>{topic.label}</TagLabel>
              <TagCount>{topic.count}</TagCount>
            </Tag>
          ))}
        </div>
      </fieldset>
    </div>
  )
}

Long label

Truncate a long tag label inside a narrow container. The full text stays in the DOM and in a title attribute. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Tag,
  TagClose,
  TagDot,
  TagLabel,
} from "@/components/ui/tag"

export function TagLongLabel() {
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <div className="w-48">
        <Tag className="max-w-full">
          <TagDot color="information" />
          <TagLabel title="Quarterly planning and roadmap review">Quarterly planning and roadmap review</TagLabel>
          <TagClose label="Remove filter" />
        </Tag>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Tag

Show a compact, removable or selectable label, such as a filter, a topic or a person.

Tag props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
size"sm" | "md" | "lg" | null | undefined"md"Height, padding and text size. sm is 24px tall, md 28px and lg 32px; every built-in action keeps a 24x24 target.
Inherited props (13)
Tag inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

TagAvatar

A small leading avatar: an image when src is set, otherwise the initials in children. Decorative by default because the tag label already names the person.

TagAvatar props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
srcstring | undefined—Image URL. When absent or while it fails to load, children (usually initials) are shown.
altstring | undefined""Text alternative for the image. Leave empty when the tag label names the same person.
Inherited props (13)
TagAvatar inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

TagCheckbox

A checkbox that makes the tag selectable. It is named by TagLabel unless you pass aria-label or aria-labelledby.

TagCheckbox props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (22)
TagCheckbox inherited props
PropTypeDefaultDescription
checkedCheckboxPrimitive.CheckedState | undefined—Current checked state. Apply the requested value from onCheckedChange when the parent owns this state.
defaultCheckedCheckboxPrimitive.CheckedState | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
onCheckedChange((checked: CheckboxPrimitive.CheckedState) => void) | undefined—Receive the next checked state. Apply it to checked when the parent controls the component.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

TagClose

A button that removes the tag. Its accessible name is "Remove" plus the tag label unless you pass aria-label.

TagClose props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
labelstring | undefined"Remove"Verb announced before the tag label, for example "Remove" or "Clear filter". Ignored when aria-label or aria-labelledby is set.
Inherited props (18)
TagClose inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined"button"Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

TagCount

A count that qualifies the label, such as the number of results for a filter.

TagCount props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
TagCount inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

TagDot

A decorative status dot. The tag text, not the color, carries the meaning.

TagDot props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
color"primary" | "neutral" | "error" | "success" | "warning" | "information" | "highlight" | undefined"success"Semantic color role of the dot. Decorative only; keep the meaning in the label text.
Inherited props (13)
TagDot inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

TagLabel

The visible text of the tag. Its ID names the tag's checkbox and close button.

TagLabel props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
TagLabel inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/tag.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Applied filters or chosen values that people can remove one by one.
  • Topics, skills or categories that people can select from a set with checkboxes.
  • Short attributes of an item, such as a person's team or a document's visibility, with a leading dot, avatar or icon.

When not to use

  • A status that never changes and needs no action; a badge is lighter.
  • A single on/off choice that applies immediately; use a switch or a toggle.
  • Navigation between views; use tabs or links.

Anatomy

Tag
Inline container with size (sm, md, lg). Provides the label ID to its actions.
TagLabel
Visible text; truncates and names TagCheckbox and TagClose.
TagDot / TagAvatar / leading icon
Optional decorative leading content.
TagCount
Optional count; add visually hidden text when the number needs context.
TagCheckbox
Optional Radix checkbox that makes the tag selectable; 24x24 hit area.
TagClose
Optional native button named 'Remove' plus the label; 24x24 target.

Keyboard & interaction

  • TagCheckbox toggles with Space and pointer; checked and onCheckedChange are consumer-owned.
  • TagClose activates with Enter, Space and pointer; the consumer removes the tag and moves focus.
  • Both actions show a visible focus outline on keyboard focus.
  • A tag without actions is not focusable and has no interaction states.

Responsive behavior

  • Tags wrap in a flex container; a single tag truncates its label rather than overflowing.
  • Built-in actions keep at least a 24x24 target at every size.
  • On touch screens prefer the lg size when tags are the main way to edit a set.

Content guidelines

  • Keep labels to one to three words.
  • Use sentence case and no trailing punctuation.
  • Give counts context with visually hidden text, such as '24 messages'.

Alternatives

  • Badge — Passive status or count text without actions.
  • Toggle group — A pressed set of options that act like buttons rather than labels.
  • Checkbox — A standard list of choices with full-width labels.
  • Combobox — Choosing many values from a long, searchable list.

Resources