Skip to content
English

How it works

Tags are a list before a plain input, so screen readers count them and the field wraps onto new rows as it fills. The first Backspace in an empty field marks the last tag in the accent colour; the second removes it, so one stray key never deletes work. Duplicates, rejected values and a full list give a 360ms shake instead of a silent no-op.

Use it for

  • Free-form keywords: topics on a post, labels on a task, skills on a profile.
  • A list of short values typed by hand, such as email recipients, where pasting many at once should work.

Look elsewhere when

  • The values come from a fixed list only: use a multi-select or chip group.
  • One value: use a text input or select.

Usage

import { useState } from 'react'
import { TagsInput } from './TagsInput.jsx'

export function RecipeTags() {
  const [tags, setTags] = useState(['breakfast'])
  return (
    <>
      <label htmlFor="tags">Tags</label>
      <TagsInput
        id="tags"
        value={tags}
        onChange={setTags}
        suggestions={['brunch', 'quick', 'sweet', 'weekend']}
        max={6}
      />
    </>
  )
}

Props

PropTypeDefaultWhat it does
valuestring[]—Controlled list of tags.
defaultValuestring[][]Initial tags when uncontrolled.
onChange(tags: string[]) => void—Called with the new list after a tag is added or removed.
suggestionsstring[][]Values offered while typing; up to six that contain the text and are not yet tags are shown, with the match highlighted.
maxnumber—Maximum number of tags; a counter appears and the field locks when full.
separatorsstring[][',', ';']Keys that commit the text besides Enter; pasted text is also split on them and on new lines.
allowDuplicatesbooleanfalseAllow the same tag twice (compared without case).
validate(tag: string) => boolean—Return false to reject a tag; the field gives a short shake.
placeholderstring'Add a tag'Hint shown while there are no tags.
disabledbooleanfalseDisables typing and removing.
invalidbooleanfalseDanger outline and aria-invalid; link your message with aria-describedby.
labelsobject—Replaces built-in text: remove, suggestions, added, removed, limit.
...restHTMLAttributes<HTMLDivElement>—Go to the root. id and the aria-label / labelledby / describedby attributes go to the input. Suggestion layer: --ds-tags-z (default 30).

Accessibility

  • The input is a combobox with aria-autocomplete="list"; the suggestions are a listbox and the highlighted one is announced through aria-activedescendant.
  • Keyboard: Enter, comma or semicolon add; Down / Up move through suggestions, Tab or Enter take one, Esc closes them; Backspace marks then removes the last tag.
  • Added and removed tags are announced in a polite live region. Remove buttons are labelled "Remove <tag>" and stay out of the Tab order, since Backspace covers them.
  • Remove buttons are 30 × 32px and suggestion rows grow to 44px on touch. Reduced motion turns off the pop, the shake and the sheet animation.

Motion

New tags pop from scale 0.7 with a 320ms spring. The field turns white with an accent halo over 220ms ease-out. Suggestions drop 4px and scale from 0.97 in 200ms. A rejected value shakes the field ±3px over 360ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

TagsInput.jsxtags-input.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Form inputs
Availability grid comes with Pro. Its preview shows once you unlock it.
Boolean operations comes with Pro. Its preview shows once you unlock it.
Cascader comes with Pro. Its preview shows once you unlock it.