A dark Bootstrap 6 tag input built on the new Chips component. Typed values become removable chips, suggested tags can be added with one click, and a live card preview shows how the tags will look on the published post. Use it for blog editors, product attributes, skills fields or any "add a few keywords" form.
How it works
The field is a .chip-input with data-bs-chips, data-bs-max-chips="8" and data-bs-separator=",". The starting .chip elements and the .form-ghost text input sit inside it. script.js imports Chips from the Bootstrap bundle and calls Chips.getOrCreateInstance(box) before Bootstrap's own DOMContentLoaded data API runs, so both share one instance. Chips handles the core behavior. Enter or a comma creates a chip, and pasting a comma-separated list adds several at once. Backspace in an empty input selects the last chip, and a second Backspace removes it. Arrow keys, Home and End move between chips, and each chip gets a dismiss button.
The script listens to three Chips events. In add.bs.chips, the normalize() function lowercases the value, turns spaces into hyphens and strips a leading #. If the cleaned value differs, it cancels the event and adds the clean version, which also catches duplicates such as "CSS" vs "css". remove.bs.chips remembers what was removed for the announcement. change.bs.chips calls render(). That updates the hidden .tic-value input, the counter, each dismiss button's aria-label, the hidden state of .tic-suggestion buttons and the #tag list in .tic-card-tags. A capture-phase keydown listener explains why Enter did nothing when a tag already exists or the limit is reached.
Customization
data-bs-max-chipson.tic-input: changes the tag limit. The counter and the intro text read it automatically.data-bs-separatoron.tic-input: use another character, for example;, to split pasted lists.--tic-accentand--tic-chip-bgon.tic-root: change the teal accent and chip fill.--tic-bg,--tic-paneland--tic-lineon.tic-root: set the page, panel and border colors.- Add or remove
.tic-suggestionbuttons. Each needs adata-tic-tagvalue in the cleaned format. - Edit
normalize()inscript.jsto allow capitals or other characters. - Read
.tic-value(nametags) on submit; it holds the comma-separated list.
Use cases
- Blog and CMS editors: authors type tags, press Enter or comma, and see a live post card preview
- Product listings: sellers add attributes as removable chips, with a limit of eight tags
- Profile and skills fields: suggested tags can be added with one click
- Search and filter inputs: pasting a comma-separated list adds several tags at once
Accessibility
The ghost input has a real <label> and points to the help text and the status line with aria-describedby. .tic-msg is a polite live region, so adds, removals, duplicates and the limit are announced. Every dismiss button gets a specific label such as "Remove css". Suggested tags are real buttons in a labelled group, and keyboard focus moves to the next suggestion when one is used. Chips show a visible teal outline on focus.
Bootstrap 6 notes
Bootstrap 5 had no tag input, so most projects pulled in a plugin. Bootstrap 6 ships .chip, .chip-input and the Chips JavaScript component, with options as data-bs-* attributes and events such as add.bs.chips and change.bs.chips. Buttons use btn-outline theme-secondary instead of btn-outline-secondary. This is built on 6.0.0-alpha.1, and the alpha APIs may still change.