Free and open-source React tag components built for modern applications and websites. These tags are built using React Aria and styled with Tailwind CSS.
Installation
You can add this tags component using our CLI or manually:
npx untitledui@latest add tags
Tags examples
Below are examples and variations of this tags component:
Sizes
Our tags component comes with three predefined sizes: sm, md, and lg. You can set the size using the size prop on the TagGroup component, which will apply to all tags within that group.
Close X
Tags can be dismissible by using the onRemove prop on the TagGroup component or the onClose prop on individual Tag components. This will add a remove button to the tag that, when clicked, will trigger the callback function with the key of the tag that was removed.
Count
Tags can display a count next to the tag by passing a number to the count prop on the Tag component. This is useful when you want to display the number of items associated with the tag.
Checkbox
You can make the tags selectable by passing either "single" or "multiple" to the selectionMode prop on the TagGroup component. This will allow users to select one or multiple tags at once.
Checkbox close X
If you'd like to make selectable tags dismissible, you can pass the onRemove prop to the TagGroup component. This will add a remove button to the tags that, when clicked, will trigger the callback function with the key of the tag that was removed.
Checkbox count
Selectable tags can also display a count next to the tag, just like non-selectable tags, by passing a number to the count prop on the Tag component. This is useful when you want to display the number of items associated with the tag.
API reference
Tag
Import Tag from @/components/base/tags/tags. Renders React Aria’s Tag — all of its props are supported.
Props from React Aria (28)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
TagAvatar
Import TagAvatar from @/components/base/tags/tags. Renders a <div> element.
Also accepts all standard image attributes, all standard HTML attributes, all aria-* attributes, all standard React DOM event handlers.
TagGroup
Import TagGroup from @/components/base/tags/tags. Renders React Aria’s TagGroup — all of its props are supported.
Props from React Aria (21)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
FAQs
Please refer to our frequently asked questions page for more.
Pass onRemove to TagGroup. Every tag then gets an X button, and the callback receives a Set of the removed keys, so filter those ids out of your own state. With onRemove, a focused tag can also be removed with Backspace or Delete. If you only need a close button on certain tags, pass onClose to those Tag components instead, which is called with the tag's id.
Set selectionMode on TagGroup to "single" or "multiple" (the default is "none"). Each tag then shows a checkbox, and you can track the selection with selectedKeys and onSelectionChange. In "single" mode the group sets disallowEmptySelection, so the user can't deselect the last selected tag.
Tags support "sm", "md", and "lg", with "sm" as the default. Set size on TagGroup and every Tag inside it, including its checkbox and close button, picks it up through context.
Pass avatarSrc for a leading avatar or dot for a status dot, which is green by default and can be recolored with dotClassName. If both are set, the avatar wins. Pass a number to count to show a counter after the label.
The label string isn't rendered visibly. TagGroup passes it to React Aria as the group's aria-label, so screen readers can announce what the set of tags is for. Use a short description such as "Filters" or "Selected skills".
Pass your array to TagList through items and render each entry with a function child, for example {(item) => <Tag {...item}>{item.label}</Tag>}. Give each item a unique id, because selection and removal work with those ids.
Yes. Set isDisabled on a Tag, or pass the ids to disabledKeys on TagGroup. A disabled tag can't be selected or removed. It shows a cursor-not-allowed cursor, and in selectable groups its checkbox is dimmed.