Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

Tags Input

Used to enter multiple values as tags with features like tag creation, deletion, and keyboard navigation.

Recipe
React
Saas UI
TypeScript
Press Enter or Return to add tag

Anatomy

import { TagsInput } from '@chakra-ui/react'
<TagsInput.Root>
  <TagsInput.Label />
  <TagsInput.Control>
    <TagsInput.Item>
      <TagsInput.ItemPreview>
        <TagsInput.ItemText />
        <TagsInput.ItemDeleteTrigger />
      </TagsInput.ItemPreview>
      <TagsInput.ItemInput />
    </TagsInput.Item>
    <TagsInput.Input />
  </TagsInput.Control>
</TagsInput.Root>

If you don't need to customize the individual tags, use the TagsInput.Items shortcut. It renders all tag items automatically based on the current value.

<TagsInput.Root>
  <TagsInput.Label />
  <TagsInput.Control>
    <TagsInput.Items />
    <TagsInput.Input />
  </TagsInput.Control>
</TagsInput.Root>

Examples

Basic

Tags are created when the user presses Enter or Return, and removed with Backspace or the delete trigger on each tag.

React
Saas UI
TypeScript
Press Enter or Return to add tag

Sizes

Use the size prop to adjust the size of the tags input.

React
Saas UI
TypeScript
React
Saas UI
TypeScript
React
Saas UI
TypeScript
React
Saas UI
TypeScript

Variants

Use the variant prop to change the visual style of the tags input.

React
Saas UI
TypeScript
React
Saas UI
TypeScript
React
Saas UI
TypeScript

Controlled

Use the value and onValueChange props to programmatically control the tags.

React
Saas UI

Max Tags

Pass the max prop to the TagsInput.Root component to limit the number of tags that can be added. Combine it with the validate prop to only accept tags that pass your own validation rules.

sage@company.com
You've invited 1 / 3 guests to your event

Editable Tags

Use the editable prop to enable inline editing of existing tags by double clicking or pressing Enter when highlighted, allowing users to quickly update tag values.

React
Saas UI
Use the arrow keys to navigate and press Enter to edit

Field

Compose the TagsInput component with the Field component to add helper text and error messages. This example also uses the delimiter and addOnPaste props so users can paste a comma separated list of emails.

sage@company.com
Add emails separated by commas

Props

Root

PropDefaultType
addOnPaste false
boolean

Whether to add a tag when you paste values into the tag input

allowDuplicates false
boolean

Whether to allow duplicate tags.

delimiter '\',\''
string | RegExp

The character that serves has: - event key to trigger the addition of a new tag - character used to split tags when pasting into the input

editable true
boolean

Whether a tag can be edited after creation, by pressing `Enter` or double clicking.

max 'Infinity'
number

The max number of tags

sanitizeValue '(value) => value.trim()'
(value: string) => string

Function to sanitize the tag value before adding. Useful for trimming whitespace, normalizing case, or stripping special characters.

colorPalette 'gray'
'base' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'sidebar' | 'sidebar.accent' | 'interaction' | 'accent' | 'presence' | 'status' | 'slate'

The color palette of the component

size 'md'
'xs' | 'sm' | 'md' | 'lg'

The size of the component

variant 'outline'
'outline' | 'subtle' | 'flushed'

The variant of the component

allowOverflow
boolean

Whether to allow tags to exceed max. In this case, we'll attach `data-invalid` to the root

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
autoFocus
boolean

Whether the input should be auto-focused

blurBehavior
'clear' | 'add'

The behavior of the tags input when the input is blurred - `"add"`: add the input value as a new tag - `"clear"`: clear the input value

defaultInputValue
string

The initial tag input value when rendered. Use when you don't need to control the tag input value.

defaultValue
string[]

The initial tag value when rendered. Use when you don't need to control the tag value.

disabled
boolean

Whether the tags input should be disabled

form
string

The associate form of the underlying input element.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string input: string hiddenInput: string clearBtn: string label: string control: string item: (opts: ItemProps) => string itemDeleteTrigger: (opts: ItemProps) => string itemInput: (opts: ItemProps) => string }>

The ids of the elements in the tags input. Useful for composition.

inputValue
string

The controlled tag input's value

invalid
boolean

Whether the tags input is invalid

maxLength
number

The max length of the input.

name
string

The name attribute for the input. Useful for form submissions

onFocusOutside
(event: FocusOutsideEvent) => void

Function called when the focus is moved outside the component

onHighlightChange
(details: HighlightChangeDetails) => void

Callback fired when a tag is highlighted by pointer or keyboard navigation

onInputValueChange
(details: InputValueChangeDetails) => void

Callback fired when the input value is updated

onInteractOutside
(event: InteractOutsideEvent) => void

Function called when an interaction happens outside the component

onPointerDownOutside
(event: PointerDownOutsideEvent) => void

Function called when the pointer is pressed down outside the component

onValueChange
(details: ValueChangeDetails) => void

Callback fired when the tag values is updated

onValueInvalid
(details: ValidityChangeDetails) => void

Callback fired when the max tag count is reached or the `validateTag` function returns `false`

placeholder
string

The placeholder text for the input

readOnly
boolean

Whether the tags input should be read-only

required
boolean

Whether the tags input is required

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

validate
(details: ValidateArgs) => boolean

Returns a boolean that determines whether a tag can be added. Useful for preventing duplicates or invalid tag values.

value
string[]

The controlled tag value

Item

PropDefaultType
index *
string | number

value *
string

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
disabled
boolean