Tag Properties
Versatile UI elements for displaying metadata, categories, or labels with default and stroke variants. Supports disabled states and can be styled to match your design system.
Installation
Add Tag to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Tag.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-slotclass-variance-authorityreact-iconsif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Create or update your Tag component
Copy this code to create your Tag component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Stroke
Stroke variant provides an outlined appearance for more subtle visual presence.
Disabled
Disabled tags appear visually muted and cannot be interacted with.
With Icons
Icons can be added to tags to provide additional visual context.
With Dismissable
Add a Tag.DismissButton to let users remove tags. It is named "Remove" for screen readers by default; pass an aria-label such as "Remove Info Tag" to make each one distinct.
With Image
Tags can include avatar images for user-related information or profile indicators. Compose them with the Avatar component inside Tag.Root.
API Reference
The Tag component provides a flexible way to display metadata, categories, or labels in your interface. It is made of Tag.Root, Tag.Icon and Tag.DismissButton; Root and DismissButton use Radix UI's Slot primitive for asChild composition.
Tag.Root
Main tag component with default and stroke variants. Uses Radix UI's Slot primitive when asChild prop is true.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default""stroke" | "default" | Visual style variant of the tag |
disabled | "boolean" | "false" | Mutes the tag and disables its Tag.DismissButton |
className | "string" | "undefined" | Additional CSS classes (merged last, so they win) |
asChild | "boolean" | "false" | When true, component will render as a child using Radix UI Slot |
Tag.Icon
Adds a decorative icon (aria-hidden) to the tag for additional visual context. Forwards its ref to the rendered icon.
| Prop | Type | Default | Description |
|---|---|---|---|
as | "React.ElementType""ReactElement" | "undefined" | The icon: a component (as={RiPushpinFill}) or an element (as={<RiPushpinFill />}). From a Server Component, pass an element. |
size | "md""sm" | "md" | Icon size (16px / 12px). The legacy names default and small are still accepted. |
Tag.DismissButton
An icon-only button (type="button") that removes the tag. Uses Radix UI's Slot primitive when asChild prop is true.
| Prop | Type | Default | Description |
|---|---|---|---|
onClick | "function" | "undefined" | Called when the dismiss button is activated (click, Enter or Space) |
aria-label | "string" | ""Remove"" | Accessible name of the icon-only button, e.g. "Remove Design". Custom children must provide their own name. |
size | "md""sm" | "md" | Button size. The legacy names default and small are still accepted. |
disabled | "boolean" | "false" | Disables the button; it is also disabled when Tag.Root is disabled |
asChild | "boolean" | "false" | Render your own single child element (with its own content and name) instead of the built-in button |