A tag input is a text field that turns each entry into a removable chip when the user presses Enter or types a comma. To build one that works for everyone, keep a real <label> and <input>, render the tags as a list of chips with labelled remove buttons, announce every change in a status region, and submit the values with the form.
That is the whole pattern. The rest of this guide is working code: a dependency-free version, a React version that shares the same logic, and the small decisions that separate a usable tag input from a fragile one. HorizonX does not sell a tag input component today, so the code here is the deliverable. For other form controls you can edit and export, see the HorizonX form controls collection.
Tag input, tags input, input chips: the same control
The names are interchangeable. Material Design's chip documentation defines input chips as chips that "represent discrete pieces of information entered by a user, such as Gmail contacts or filter options within a search field", and states that all input chips are removable (Material Web chip docs). Material lists four chip types: assist, filter, input and suggestion. Only input chips are created by typing. The other three are buttons or toggles that happen to look like pills.
That distinction matters before you write any code, because if users pick from a list you already know, you probably do not need a tag input at all.
Tag input or something else? A decision table
| Situation | Better control | Reason |
|---|---|---|
| Free text, any value allowed (keywords, skills, labels) | Tag input | Users type values you cannot list in advance |
| Short fixed list you can show in full | Checkbox group | Every option is visible and keyboard support is native |
| One choice among two to four options | Radio group or segmented control | One decision, one click |
| Long known list (countries, teammates) | Multi-select combobox that renders chips | Typing filters suggestions; follow the WAI-ARIA combobox pattern |
| Long known list, minimal effort | <select multiple> |
Native, but on desktop picking several items means holding Ctrl, Command or Shift while clicking (MDN select) |
| Several email addresses | <input type="email" multiple>, or a tag input that validates each chip |
The native field accepts a comma-separated list (MDN email input) |
For the fixed-list rows, Glass Radio is a three-option selector built on real radio inputs that stay in the tab order, and styling a checkbox group is covered in custom checkbox CSS.
Behaviour checklist
Each item below is handled in the code that follows. Use it to review any tag input, including one from a library.
- Enter or comma turns the current text into a tag. Enter in an empty field submits the form as usual.
- Pasting
react, vue, sveltecreates three tags. - Values are trimmed, inner spaces are collapsed and duplicates are rejected without regard to case, with a message that says so.
- Backspace in an empty field removes the last tag.
- Every chip has its own remove button with a name like "Remove react" and a target of at least 24 by 24 CSS pixels (WCAG 2.5.8 Target Size).
- After a chip is removed, focus goes back to the text field, because the button that had focus no longer exists.
- Additions, removals and rejections are announced through a
role="status"region (WCAG 4.1.3 Status Messages). - Japanese, Chinese and Korean input works: Enter that confirms an IME candidate does not create a tag. The code checks
event.isComposing(Chrome 56, Firefox 31, Safari 10.1 per MDN browser compat data, checked 2026-10-09). - The form submits real values. One hidden input per tag means
FormData.getAll('skills')returns an array, so commas never need escaping. - Leaving the field with text in it keeps that text as a tag instead of dropping it silently.

The markup
<form>
<div class="tag-input" data-name="skills">
<label for="skills-field">Skills</label>
<p id="skills-hint" class="hint">Press Enter or comma to add a tag. Backspace in an empty field removes the last one.</p>
<div class="tag-box">
<ul class="tag-list" role="list" aria-label="Selected skills"></ul>
<input id="skills-field" class="tag-field" type="text" autocomplete="off" aria-describedby="skills-hint">
</div>
<div class="tag-values"></div>
<p class="visually-hidden" role="status"></p>
</div>
</form>
Three details are deliberate. The visible label and hint are linked to the field with for and aria-describedby, so the instructions are read when the field gets focus. The list has role="list" because WebKit removes list semantics from lists styled with list-style: none (Scott O'Hara on lists and Safari). The status paragraph is in the page from the start and only its text changes, which is the reliable way to get a live region announced.
Shared logic: tag-logic.js
These helpers have no DOM access, so the vanilla and React versions use the same rules.
// Pure helpers: no DOM, so the same code works in the vanilla and React versions.
export function splitTags(raw) {
return raw
.split(/[,\n]/)
.map((part) => part.trim().replace(/\s+/g, ' '))
.filter(Boolean);
}
export function addTags(current, incoming, { max = Infinity, maxLength = 32 } = {}) {
const tags = [...current];
const seen = new Set(current.map((tag) => tag.toLowerCase()));
const added = [];
const rejected = [];
for (const tag of incoming) {
const key = tag.toLowerCase();
if (tag.length > maxLength) rejected.push({ tag, reason: 'is too long' });
else if (seen.has(key)) rejected.push({ tag, reason: 'is already added' });
else if (tags.length >= max) rejected.push({ tag, reason: `was not added: limit of ${max} tags` });
else {
seen.add(key);
tags.push(tag);
added.push(tag);
}
}
return { tags, added, rejected };
}
export function describeChange(added, rejected) {
const parts = [];
if (added.length) parts.push(`Added ${added.join(', ')}.`);
for (const { tag, reason } of rejected) parts.push(`${tag} ${reason}.`);
return parts.join(' ');
}
Vanilla JavaScript: tag-input.js
Load it with <script type="module" src="tag-input.js"></script>.
import { splitTags, addTags, describeChange } from './tag-logic.js';
function createTagInput(root, { max = 8 } = {}) {
const field = root.querySelector('.tag-field');
const list = root.querySelector('.tag-list');
const values = root.querySelector('.tag-values');
const status = root.querySelector('[role="status"]');
const name = root.dataset.name;
let tags = [];
function render() {
list.replaceChildren(
...tags.map((tag, index) => {
const item = document.createElement('li');
item.className = 'tag';
const text = document.createElement('span');
text.textContent = tag;
const remove = document.createElement('button');
remove.type = 'button';
remove.className = 'tag-remove';
remove.setAttribute('aria-label', `Remove ${tag}`);
remove.textContent = '×';
remove.addEventListener('click', () => removeAt(index));
item.append(text, remove);
return item;
})
);
// One hidden input per tag, so FormData.getAll(name) returns an array.
values.replaceChildren(
...tags.map((tag) => Object.assign(document.createElement('input'), { type: 'hidden', name, value: tag }))
);
}
function commit(raw) {
const result = addTags(tags, splitTags(raw), { max });
tags = result.tags;
field.value = '';
render();
status.textContent = describeChange(result.added, result.rejected);
}
function removeAt(index) {
const [removed] = tags.splice(index, 1);
render();
field.focus(); // the button that had focus no longer exists
status.textContent = `Removed ${removed}.`;
}
field.addEventListener('keydown', (event) => {
if (event.isComposing) return; // IME still composing: Enter confirms the word, not the tag
if ((event.key === 'Enter' || event.key === ',') && field.value.trim()) {
event.preventDefault();
commit(field.value);
} else if (event.key === 'Backspace' && field.value === '' && tags.length) {
removeAt(tags.length - 1);
}
});
field.addEventListener('paste', (event) => {
const text = event.clipboardData.getData('text');
if (!/[,\n]/.test(text)) return;
event.preventDefault();
commit(field.value + ',' + text);
});
field.addEventListener('blur', () => {
if (field.value.trim()) commit(field.value);
});
return { get value() { return [...tags]; } };
}
createTagInput(document.querySelector('.tag-input'), { max: 8 });
Backspace removes the last tag immediately and announces it. Some products highlight the chip on the first press and delete it on the second, which is safer for long tags; if you choose that, show the highlighted state visibly and announce it too.
The CSS
.tag-box {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.375rem;
padding: 0.375rem 0.5rem;
border: 1px solid #6b7280;
border-radius: 0.5rem;
background: #fff;
}
.tag-box:focus-within {
outline: 2px solid #192c46;
outline-offset: 2px;
}
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 0.375rem;
margin: 0;
padding: 0;
list-style: none;
}
.tag-list:empty { display: none; }
.tag {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.125rem 0.25rem 0.125rem 0.625rem;
border-radius: 999px;
background: #e8ecf2;
color: #192c46;
font-size: 0.875rem;
}
.tag-remove {
display: grid;
place-items: center;
inline-size: 1.5rem;
block-size: 1.5rem;
border: 0;
border-radius: 50%;
background: transparent;
color: inherit;
font-size: 1rem;
cursor: pointer;
}
.tag-remove:hover { background: #d3dae5; }
.tag-remove:focus-visible { outline: 2px solid #192c46; }
.tag-field {
flex: 1 0 8ch;
min-inline-size: 8ch;
border: 0;
padding: 0.25rem;
font: inherit;
background: transparent;
}
.tag-field:focus { outline: none; } /* the box draws the ring via :focus-within */
.visually-hidden {
position: absolute;
inline-size: 1px;
block-size: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
The focus ring sits on the whole box through :focus-within, so the field can drop its own outline without losing a visible focus indicator. Remove buttons keep their own :focus-visible ring.

React tag input
The React version reuses tag-logic.js. Keys use the lowercased tag, which is safe because duplicates are rejected without regard to case.
import { useId, useRef, useState } from 'react';
import { splitTags, addTags, describeChange } from './tag-logic.js';
export function TagInput({ label, name, hint, max = 8, defaultValue = [] }) {
const [tags, setTags] = useState(defaultValue);
const [draft, setDraft] = useState('');
const [message, setMessage] = useState('');
const id = useId();
const fieldRef = useRef(null);
function commit(raw) {
const result = addTags(tags, splitTags(raw), { max });
setTags(result.tags);
setDraft('');
setMessage(describeChange(result.added, result.rejected));
}
function removeAt(index) {
setMessage(`Removed ${tags[index]}.`);
setTags(tags.filter((_, i) => i !== index));
fieldRef.current?.focus(); // the clicked button is about to unmount
}
function onKeyDown(event) {
if (event.nativeEvent.isComposing) return;
if ((event.key === 'Enter' || event.key === ',') && draft.trim()) {
event.preventDefault();
commit(draft);
} else if (event.key === 'Backspace' && draft === '' && tags.length) {
removeAt(tags.length - 1);
}
}
function onPaste(event) {
const text = event.clipboardData.getData('text');
if (!/[,\n]/.test(text)) return;
event.preventDefault();
commit(`${draft},${text}`);
}
return (
<div className="tag-input">
<label htmlFor={`${id}-field`}>{label}</label>
{hint && <p id={`${id}-hint`} className="hint">{hint}</p>}
<div className="tag-box">
<ul className="tag-list" role="list" aria-label={`Selected ${label.toLowerCase()}`}>
{tags.map((tag, index) => (
<li className="tag" key={tag.toLowerCase()}>
<span>{tag}</span>
<button type="button" className="tag-remove" aria-label={`Remove ${tag}`} onClick={() => removeAt(index)}>
{'×'}
</button>
</li>
))}
</ul>
<input
ref={fieldRef}
id={`${id}-field`}
className="tag-field"
type="text"
autoComplete="off"
aria-describedby={hint ? `${id}-hint` : undefined}
value={draft}
onChange={(event) => setDraft(event.target.value)}
onKeyDown={onKeyDown}
onPaste={onPaste}
onBlur={() => draft.trim() && commit(draft)}
/>
</div>
{tags.map((tag) => <input key={tag.toLowerCase()} type="hidden" name={name} value={tag} />)}
<p className="visually-hidden" role="status">{message}</p>
</div>
);
}
How the code was checked
On 2026-10-09 the logic passed assertion tests in Node 22, and both versions ran in Chromium with scripted keyboard and paste events: Enter and comma add tags, a duplicate in a different case is rejected and announced, Backspace removes the last tag, clicking a remove button returns focus to the field, a pasted list respects the limit, FormData returns one value per tag, Enter with isComposing set adds nothing, and remove buttons measure 24 by 24 pixels. The CSS passed csstree-validator. Screen reader output was not tested; check it with VoiceOver and NVDA before you ship.
FAQ
What is chip in UI design?
Material describes chips as elements that "help people enter information, make selections, filter content, or trigger actions". Its four types are assist chips (common actions, such as adding an event to a calendar), filter chips (tags used to filter content), input chips (pieces of information entered by a user, such as event attendees) and suggestion chips (dynamic suggestions, such as message replies). A tag input produces input chips.
Is there a native HTML tag input?
No. The closest native options are <input type="email" multiple>, which accepts a comma-separated list of addresses, and <select multiple> for known options. Neither renders chips, so a custom component like the one above is the usual answer.
Should I use a React tag input library?
Use one when you need suggestions from a server, drag to reorder or per-chip validation, and check it against the checklist above before you adopt it. If your design system is built on Tailwind, the React and Tailwind component library comparison shows what each library covers.
Next step
Copy the four files, change the label, name and limit, and run through the checklist with a keyboard. For switches, radios, selectors and search fields that sit next to a tag input in the same form, browse the HorizonX form controls collection.