Monsoon v0.2.0
Made by Alexandre Kohler Star

Interactive

Tags input

Chips over a plain text input that keeps a comma separated value. Enter or comma adds, Backspace removes the last tag, a pasted list is split, duplicates flash, and there are suggestions and a maximum. Needs monsoon.js.

Interactive5 classesNeeds monsoon.jsLight and dark

Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.

Example

Full

JavaScript API

Attribute

data-m-tags-input

Options

OptionDescription
data-m-tags-input-max="5"
data-m-tags-input-suggestions="css,html,js"
data-m-tags-input-separator=","
data-m-tags-input-add-on-blur="false"

Methods

MethodDescription
Monsoon.tagsInput(el).tags
Monsoon.tagsInput(el).add("css")
Monsoon.tagsInput(el).remove("css")
Monsoon.tagsInput(el).clear()

Events

EventDescription
monsoon:change { tags }
monsoon:tag-add { tag } (cancelable)
monsoon:tag-remove { tag }

Classes

5 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.

ClassTypeWhat it does
Base Base class of the tags input. On a <div> in the example. Sets block display, width, flex display, alignment, gap and height, and --tone.
CSS
.tags-input {
  display: block;
  width: 100%;
}

.tags-input[data-full] > .tags-input-field::placeholder {
  color: transparent;
}
Modifier Modifier, combined with the tags-input class. Not used in the example above. Sets contents display.
CSS
.tags-input-tags {
  display: contents;
}
Modifier Modifier, combined with the tags-input class. Not used in the example above. Sets inline-flex display, alignment, gap, width, height and padding.
CSS
.tags-input-tag[data-flash] {
  animation: m-ix-flash .5s var(--m-ease);
}

@media (prefers-reduced-motion: reduce) {
  .datepicker-panel,
  .combobox-list,
  .color-picker-panel,
  .data-table-menu,
  .select-menu-popup,
  .tags-input-tag,
  .carousel-auto .carousel-dot::after {
    animation: none;
  }
}
Modifier Modifier, combined with the tags-input class. Not used in the example above. Sets grid display, alignment, width, height, text color and corner radius.
CSS
.tags-input-remove:hover {
  opacity: 1;
  background-color: color-mix(in oklab, currentColor 14%, transparent);
}

.tags-input-remove:focus-visible {
  opacity: 1;
  outline: var(--m-ring);
  outline-offset: var(--m-ring-offset);
}
Modifier Modifier, combined with the tags-input class. Not used in the example above. Sets alignment, width, height, padding, text size and text color.
CSS
.combobox-control > .combobox-input, .tags-input-field {
  flex: 1 1 6rem;
  min-width: 6rem;
  height: calc(var(--field-h, var(--m-control-h-md)) - .5rem - 2px);
  padding: 0 .25rem;
  font-size: var(--field-fs, var(--m-control-fs-md));
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
}

.tags-input[data-full] > .tags-input-field::placeholder {
  color: transparent;
}

Usage

The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.

index.html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>

<!-- Tags input: start from the base class, then add modifiers -->
<div class="field max-w-md">
  <label class="label" for="ti-topics">Topics</label>
  <div class="tags-input" data-m-tags-input data-m-tags-input-max="6" data-m-tags-input-suggestions="accessibility,animation,css,dark mode,design tokens,forms,javascript,performance,typography">
    <input id="ti-topics" class="input" name="topics" value="css, design tokens" placeholder="Add a topic">
  </div>
  <p class="hint">Up to 6 topics. Paste a comma separated list to add many.</p>
</div>

Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.

Accessibility

  • Give every control a visible label linked with for, or an aria-label when the purpose is obvious from context. Link help and error text with aria-describedby; invalid styles use :user-invalid, so they appear only after the user interacts.
  • Every interactive part shows a visible focus ring with :focus-visible, and tone colors pair with -foreground tokens that keep text at 4.5:1 or better in light and dark mode.

No recent searches

Try , , or .

Recent

Loading the search index

No results for ""

Check the spelling, or search a class name such as px-4.