# Checkbox Chips

> Toggleable filter chips made from checkboxes, with a check icon when selected.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: chips, tags, filter, checkbox, multi-select
- Live preview: https://copy-css.com/snippets/checkbox-chips
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<fieldset class="chips">
  <legend>Topics</legend>
  <label><input type="checkbox" checked>Design</label>
  <label><input type="checkbox">Code</label>
  <label><input type="checkbox" checked>Motion</label>
  <label><input type="checkbox">Audio</label>
</fieldset>
```

## CSS

```css
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 280px;
  margin: 0;
  padding: 0;
  border: 0;
  font: 500 14px/1 system-ui, sans-serif;
}

.chips legend {
  width: 100%;
  margin-bottom: 10px;
  color: #3f3f46;
  font-weight: 700;
}

.chips label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1.5px solid #e4e4e7;
  border-radius: 999px;
  color: #3f3f46;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chips input {
  flex: none;
  color: inherit;
  width: 0;
  height: 14px;
  margin: 0 -6px 0 0; /* hides the gap while unchecked */
  border: 0;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  appearance: none;
  transition: width 0.15s ease, margin 0.15s ease;
}

.chips label:has(:checked) {
  border-color: #18181b;
  background: #18181b;
  color: #fff;
}

.chips input:checked {
  width: 14px;
  margin-right: 0;
}

.chips label:has(:focus-visible) {
  outline: 2px solid #18181b;
  outline-offset: 2px;
}
```

## Notes

- This CSS Checkbox Chips is 59 lines of pure CSS (1.5 KB) with no JavaScript and no dependencies. It uses transitions, masks, Flexbox and the :has() selector.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
