Chips
Small pieces for people, places, tags and choices. A chip can carry an icon or an avatar, be removed, or be pressed like a filter.
Basic
.chip on a <span>. Put a Moey icon or an avatar first; paint it with .bg-<color> or .bg-<color>-soft.
<div class="chip-group" id="ch-basic">
<span class="chip">Design</span>
<span class="chip"><i class="mi mi-map-pin" aria-hidden="true"></i>Lisbon</span>
<span class="chip"><span class="avatar bg-pink">AK</span>Ana Kim</span>
<span class="chip bg-yellow">Featured</span>
<span class="chip bg-green-soft"><i class="mi mi-check" aria-hidden="true"></i>In stock</span>
<span class="chip bg-red-soft">Sold out</span>
</div><span class="chip">Design</span>
<span class="chip"><i class="mi mi-map-pin"></i>Lisbon</span>
<span class="chip"><span class="avatar bg-pink">AK</span>Ana Kim</span>
<span class="chip bg-green-soft">In stock</span>Chips you can remove
Add a .chip-dismiss button with a label that says what it removes. The chip goes away and keyboard focus moves to the next one.
<div class="w-96 max-w-full">
<div class="form-label mb-2" id="ch-people-label">Shared with</div>
<div class="chip-group" id="ch-people" aria-labelledby="ch-people-label">
<span class="chip"><span class="avatar bg-pink">AK</span>Ana Kim<button class="chip-dismiss" type="button" aria-label="Remove Ana Kim"></button></span>
<span class="chip"><span class="avatar bg-cyan">MR</span>Marco Rossi<button class="chip-dismiss" type="button" aria-label="Remove Marco Rossi"></button></span>
<span class="chip"><span class="avatar bg-violet">PN</span>Priya Nair<button class="chip-dismiss" type="button" aria-label="Remove Priya Nair"></button></span>
<span class="chip"><span class="avatar bg-yellow">LF</span>Lena Fischer<button class="chip-dismiss" type="button" aria-label="Remove Lena Fischer"></button></span>
</div>
</div><span class="chip">
<span class="avatar bg-pink">AK</span>Ana Kim
<button class="chip-dismiss" type="button" aria-label="Remove Ana Kim"></button>
</span>
<script>
people.addEventListener('momo:chip-remove', (e) => {
unshare(e.detail.chip); // e.preventDefault() keeps the chip
});
</script>Chips you can press
Make the chip a <button> and wrap the row in data-momo-chips: one can be pressed at a time. data-momo-chips="multiple" lets several be pressed, and .chip-check adds a check mark to the pressed ones.
Chosen: s, m
<div class="stack" style="--stack-gap: 1.25rem">
<div>
<div class="form-label mb-2" id="ch-status-label">Order status (one)</div>
<div class="chip-group" id="ch-status" data-momo-chips data-chips-required aria-labelledby="ch-status-label">
<button class="chip" data-value="all" aria-pressed="true">All</button>
<button class="chip" data-value="paid">Paid</button>
<button class="chip" data-value="unpaid">Unpaid</button>
<button class="chip" data-value="refunded">Refunded</button>
</div>
</div>
<div>
<div class="form-label mb-2" id="ch-size-label">Sizes in stock (several)</div>
<div class="chip-group chip-check" id="ch-sizes" data-momo-chips="multiple" aria-labelledby="ch-size-label">
<button class="chip" data-value="s" aria-pressed="true">Small</button>
<button class="chip" data-value="m" aria-pressed="true">Medium</button>
<button class="chip" data-value="l">Large</button>
<button class="chip" data-value="xl" disabled>Extra large</button>
</div>
<p class="text-sm text-muted mt-3 mb-0">Chosen: <b id="ch-sizes-out">s, m</b></p>
</div>
</div>
<script>
document.getElementById('ch-sizes').addEventListener('momo:chips', function (e) {
document.getElementById('ch-sizes-out').textContent = e.detail.values.join(', ') || 'none';
});
</script><div class="chip-group chip-check" data-momo-chips="multiple" aria-label="Sizes">
<button class="chip" data-value="s" aria-pressed="true">Small</button>
<button class="chip" data-value="m">Medium</button>
</div>
<script>
sizes.addEventListener('momo:chips', (e) => console.log(e.detail.values)); // ["s", "m"]
</script>The row is one stop for the Tab key; the arrow keys move between its chips, and Space or Enter presses one. data-chips-required keeps one pressed at all times.
Sizes and shapes
.chip-sm and .chip-lg change the size. .chip-square uses Momo's normal corners. .chip-group-scroll keeps a long row on one line and lets it scroll sideways, for phones.
<div class="stack" style="--stack-gap: 1rem">
<div class="chip-group">
<span class="chip chip-sm">Small</span>
<span class="chip">Normal</span>
<span class="chip chip-lg">Large</span>
<span class="chip chip-square">Square</span>
<span class="chip chip-square"><span class="avatar bg-lime">SO</span>Sam Okafor</span>
</div>
<div class="chip-group chip-group-scroll w-80 max-w-full" id="ch-scroll" aria-label="Categories">
<a class="chip" href="#sizes-and-shapes" aria-current="page">All</a>
<a class="chip" href="#sizes-and-shapes">Bags</a>
<a class="chip" href="#sizes-and-shapes">Clothes</a>
<a class="chip" href="#sizes-and-shapes">Home</a>
<a class="chip" href="#sizes-and-shapes">Stationery</a>
<a class="chip" href="#sizes-and-shapes">Gift cards</a>
</div>
</div>Good to know
- A chip is not a badge: a badge is a small label on something else (a count, a status), a chip stands on its own and can be acted on.
- To type values and get chips (skills, email addresses), use the Tag input.
- Pressable chips work as the buttons of Filter & sort: put
data-filteron them. - The remove button is a real button with its own name, so screen readers say "Remove Ana Kim".
Reference
| Class / attribute | What it does |
|---|---|
.chip | The chip (a span; a button or a link when it can be pressed) |
.chip-dismiss | The remove button inside a chip; event momo:chip-remove (cancelable), detail: { chip } |
.chip-img | A picture at the start (an .avatar works the same way) |
.chip-sm, .chip-lg, .chip-square | Sizes, Momo's normal corners |
.chip-group, .chip-group-scroll, .chip-check | A wrapping row, a one-line scrolling row, a check on pressed chips |
data-momo-chips, ="multiple", data-chips-required | Pressable chips: one at a time, several, one always pressed |
Event momo:chips, Momo.chips(group) | detail: { values, chip }; values() and set(values) |