shadcn.io is an independent project built on shadcn/ui
Components
Free
Tags Input for Radix UI
Type a word, press Enter, and it becomes a removable chip. A tags input for React on Radix UI, with paste splitting, a tag limit and validation.
On this page9 sections
Radix UI does not include this primitive, so this page uses the Ark UI component. The visuals match the Ark UI version.
A tags input turns each entry someone types into a chip they can remove, and holds the chips as an array of strings. Enter or a comma adds the typed text as a tag. Reach for it when the values are free text with no fixed list behind them: labels on an issue, skills on a profile, the people on an invite.
When the values come from a list you already have, such as team members or countries, a Combobox with several selections lets people search that list instead.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
TagsInput draws the text field and the clear button itself, and placeholder sets the hint that field shows while the list is empty. Its children are the tags: TagsInputContext hands you the current array, and each entry becomes a TagsInputItem with its index and value. The input id in ids and the label's htmlFor tie the label to the text field.
Radix UI has no component for typing tags, so this one is built on Ark UI's tags input. The caret stays in the text field: the arrow keys and Backspace highlight a tag without moving focus to it, and a live region announces each tag as it is added or deleted. Each remove button is labeled with its tag's text and left out of the tab order. A FieldLabel beside it isn't tied to the text field, so set an input id in ids on TagsInput and give the label a matching htmlFor, as every demo on this page does.
KeyAction
Arrow Left
Moves focus to the previous tag item.
Arrow Right
Moves focus to the next tag item.
Backspace
Deletes the tag item that has visual focus. With the caret at the start of the input and no tag highlighted, it highlights the last tag item first.
Enter
When a tag item has visual focus and editable is set, it puts the tag in edit mode. When the input has focus, it adds the value to the list of tags.
Delete
Deletes the tag item that has visual focus.
Ctrl+V
When addOnPaste is set. Adds the pasted value as a tags.
Arrow Down
When a tag is highlighted, clears the highlight and goes back to typing in the text field.
EscEscape
When a tag is highlighted, clears the highlight. While a tag is being edited, cancels the edit and keeps its old text.
Tab
Moves focus from the text field to the clear button, then on to the next control.
Space
When focus is on the clear button, removes every tag and moves focus back to the text field.
Demos
Blur behavior
With blurBehavior set to add, text left in the box becomes a tag when focus moves away, so someone who types a framework and tabs to the next field doesn't lose it. Without the prop that text stays in the box but isn't part of the value, and clear empties the box instead. Pick add for forms people tab through.
Combobox
The tags input's text field doubles as the search box of a suggestion list with eight frameworks. Typing filters the list, picking a suggestion adds it through addValue, and frameworks already chosen drop out of the list. Enter with no suggestion highlighted adds whatever was typed. Use this when most tags are known in advance but people may still invent one.
Controlled
The tags, starting at React and Solid, are held in the page's own state, passed in as value and replaced from onValueChange each time one is added or removed. Control the list when something besides the field changes it, such as a reset button, a saved draft or a URL parameter. When nothing else touches it, defaultValue is enough.
Controlled input value
Two buttons above the field write React into the text box or empty it, through inputValue and onInputValueChange, while the tags stay on defaultValue. Hold the typed text in state when something outside the box fills it, such as a suggested tag or a search query. React is already a tag here, so Enter after the first button adds nothing.
Custom delimiter
Here delimiter is a regular expression that matches a comma or any whitespace, so a space after a word ends the tag just as a comma would. Use it for one-word tags such as hashtags or package names, where people expect the space bar to commit. Keep the default comma when a tag can hold a space, like a city or a full name.
Disable editing
editable is set to false here, which is also what TagsInput does when you leave the prop out, so a tag can be removed but never rewritten in place. Ark UI's own default is true, where a double click or Enter on a highlighted tag turns it back into text. Pass editable when people should fix a typo without deleting the tag, as in Editable.
Disabled
disabled on TagsInput dims the box and turns off the text field, the remove buttons and the clear button, so the three frameworks can be read but not changed. The Field around it is marked disabled as well. Use it when a setting is locked by plan or by permission, and say why next to the field.
Editable
editable turns on what TagsInput leaves off by default: a double click on a tag, or Enter on a highlighted one, turns it back into text. Enter saves the change and Escape cancels it. The hint under the field says so, since nothing on a tag shows it can be edited. Use it where typos are likely, such as skills or keywords typed in a hurry.
Field
The box sits under a FieldLabel, with a FieldDescription below it that says to press Enter, a hint that stays on screen while someone types, unlike the placeholder, which goes away once there are tags. Use this layout when the tags are one question in a longer form.
Form
The tags input sits in a form under the name labels, with Save and Reset buttons. Save reads the form's data, where the hidden input holds the tags as one string, and shows it under the buttons as "bug, frontend". Reset puts back the tags the field started with. Use this when the tags go out with an ordinary form post.
Invalid
invalid on TagsInput and on its Field sets aria-invalid on the text field, and the border turns to the error color. Set it after a failed submit, when the list as a whole breaks a rule the field can't check, such as needing at least one tag. Put the reason in words under the field, because a red border doesn't say what to fix.
Max length
maxLength is 10 here and goes onto the text field, so the browser stops accepting characters at the tenth, and the label states the limit up front. Use it for short tokens such as codes or slugs, where a pasted sentence should never become one tag. It limits the length of each tag, while max limits how many there are.
Max tags
max is 3 and two frameworks are already in, so one more is accepted, and after that Enter does nothing and the extra text waits in the box. Use a hard cap when the meaning is up to some number, such as three reviewers or five labels. The field shows no message at the limit, so state it in the label, as this one does.
Max with overflow
The cap is 3 again and the field starts full, but allowOverflow lets a fourth tag in. Past the cap, the root gets data-invalid, the text field gets aria-invalid and the error border, and onValueInvalid fires. Prefer this over a hard cap when people should see what they added and choose which tag to drop.
Paste behavior
addOnPaste is on and the field starts empty, so pasting the line React, Vue, Svelte creates three tags, split on the comma that delimiter names. Turn it on when values arrive in bulk, such as a list of invitees. Leave it off when a comma can belong inside one tag, because a paste would break that tag apart.
Sanitize value
sanitizeValue trims and lowercases the text before it becomes a tag, so typing React or REACT adds nothing, since both turn into the react already in the list. Use a sanitizer for emails, slugs and handles, where case and stray spaces shouldn't make two tags. Passing one replaces the default, which only trims, so keep the trim in yours.
Size lg
With size set to lg, the tags grow to 28 pixels with larger text and the box to at least 36 pixels. Use it when the tags input is the main control on a screen, such as the recipients line of a message composer. Adding, editing and removing tags work the same at every size.
Size md
md is the default, so this field looks the same as one with no size: 24-pixel tags in a box at least 32 pixels tall. It is the size for an ordinary form, beside inputs and selects at their own default size. Spell it out only when the size comes from a variable, such as a density setting.
Size sm
With size set to sm, the tags shrink to 20 pixels and the box to a 28-pixel minimum, for a filter bar or a table toolbar where vertical room is tight. Put it beside other small controls, because a small tags field next to default-height buttons looks out of line.
Validation
validate gets the tags so far and the text about to become a tag, and this one accepts three or more letters, digits or hyphens that aren't in the list yet. A rejected entry is cleared from the box, so onValueInvalid puts the reason under the field in a FieldError and marks it invalid until the next keystroke. Pair every validator with a message like this one.
FAQ
When should I use a Tags Input instead of a multi-select Combobox?
Use a tags input when people type values that don't exist anywhere yet: labels on an issue, keywords, email addresses. Anything typed can become a tag, subject to your validate function.
A Combobox that allows several selections fits when the values come from a list you already have, such as team members or countries, because people search it and can't pick something that isn't there. When most values are known but some will be new, the Combobox demo puts suggestions on a tags input.
How do people add and remove tags in a Tags Input?
Enter adds the typed text as a tag, and so does typing the delimiter, a comma unless you change delimiter. Each tag has its own remove button, and the clear button at the end of the box removes them all.
From the keyboard, Backspace with the caret at the start of the text field highlights the last tag, and the next press deletes it, so holding the key empties the list from the end. ArrowLeft and ArrowRight move the highlight, and Delete removes the highlighted tag.
How do I control the Tags Input value in React?
Keep the tags in state as an array of strings, pass it as value, and update it in onValueChange, which receives an object with the new array in details.value. The Controlled demo does exactly this.
defaultValue is enough when nothing but the field changes the list. Control it when a reset button, a saved draft or another field has to change the tags.
How do I limit the number of tags or stop duplicates in a Tags Input?
Set max to the most tags the list may hold. At the cap, Enter and the delimiter do nothing and the typed text waits in the box, as in Max tags, or add allowOverflow to let more in and mark the field invalid instead.
Duplicates are refused with no prop at all: a tag already in the list is dropped and the box is cleared. Set allowDuplicates if the same text may appear twice. maxLength caps the characters in each tag, not the number of tags.
How do I paste a comma-separated list into a Tags Input?
Add addOnPaste to TagsInput. A pasted line is split on the delimiter, each piece goes through sanitizeValue, and every piece becomes a tag, as the Paste behavior demo shows. Without the prop, the whole paste lands in the box and turns into one tag on Enter.
Your validate function runs once, on the whole pasted text rather than on each piece. A paste also isn't held to max: it can push the list past the cap, which marks the field invalid as allowOverflow would, and from there Enter adds more tags too.
How does a Tags Input submit its tags with a form?
Give TagsInput a name, and a hidden input submits the tags as one string joined by a comma and a space, so React and Vue arrive as "React, Vue", as the Form demo shows. Split it on the server, or, if a tag can contain a comma, keep the array in state and send it as JSON yourself.
The hidden input also follows the form: resetting the form puts back the tags the field started with. Set form to the form's id when the field sits outside the form element it belongs to.
How do I add autocomplete suggestions to a Tags Input?
Wrap it in an Autocomplete and make the tags input's text field its input, as the Combobox demo does. Create the tags input with useTagsInput, render it through TagsInputRootProvider, and wrap TagsInputInput in Ark UI's ArkCombobox.Input so the two share one field. In the onValueChange of Autocomplete, pass the picked item to addValue and keep its own value empty, so each pick becomes a tag.
Filter the chosen tags out of the suggestions, as the demo does, so nobody picks the same one twice. When every value must come from the list, a Combobox with several selections is simpler.
Why can't I edit a tag after adding it to the Tags Input?
TagsInput in components/ui/tags-input sets editable to false unless you pass it, although Ark UI's own default is true. Set editable to true, and a double click on a tag or Enter on a highlighted one turns it back into text, as in the Editable demo.
Enter saves the change and Escape cancels it. Saving an empty tag deletes it, and an edit that matches another tag leaves the old text in place. useTagsInput, which the Combobox demo uses, keeps Ark UI's default, so its tags are editable already.
API Reference
TagsInput
<div>data-slot="tags-input"
PropType
inputValue?string
The controlled tag input's value.
defaultInputValue?string
The initial tag input value when rendered.
Use when you don't need to control the tag input value.