AI CSS Animations

Checkbox Filter Chips

A row of tag chips that act as checkboxes for filters. Each chip's plus sign folds into a checkmark as the chip fills with the accent. The two bars only move with transform, so the morph stays smooth.

Also known as: css checkbox as button, checkbox chips css, make checkbox look like button.

HTML

<div class="chk-filter-chips" role="group" aria-label="Topics">
  <label class="chk-filter-chips-chip"><input type="checkbox" checked><span class="chk-filter-chips-bg"></span><span class="chk-filter-chips-icon"><i></i><i></i></span><span class="chk-filter-chips-text">Design</span></label>
  <label class="chk-filter-chips-chip"><input type="checkbox"><span class="chk-filter-chips-bg"></span><span class="chk-filter-chips-icon"><i></i><i></i></span><span class="chk-filter-chips-text">Code</span></label>
  <label class="chk-filter-chips-chip"><input type="checkbox"><span class="chk-filter-chips-bg"></span><span class="chk-filter-chips-icon"><i></i><i></i></span><span class="chk-filter-chips-text">Music</span></label>
  <label class="chk-filter-chips-chip"><input type="checkbox" checked><span class="chk-filter-chips-bg"></span><span class="chk-filter-chips-icon"><i></i><i></i></span><span class="chk-filter-chips-text">Travel</span></label>
  <label class="chk-filter-chips-chip"><input type="checkbox"><span class="chk-filter-chips-bg"></span><span class="chk-filter-chips-icon"><i></i><i></i></span><span class="chk-filter-chips-text">Food</span></label>
</div>

CSS

.chk-filter-chips {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45em;
  max-width: 15em;}
.chk-filter-chips-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4em 0.85em 0.4em 0.7em;
  font-size: 0.85em;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: color 0.25s ease;
}
.chk-filter-chips-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-filter-chips-bg {
  position: absolute;
  inset: 0;
  border: 0.09em solid color-mix(in srgb, currentColor 25%, transparent);
  border-radius: 2em;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}
.chk-filter-chips-icon {
  position: relative;
  flex: none;
  width: 0.75em;
  height: 0.75em;
}
.chk-filter-chips-icon i {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 0.15em;
  margin-top: -0.075em;
  border-radius: 1em;
  background: currentColor;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-filter-chips-icon i:first-child {
  transform: translate(0, 0) rotate(0deg) scaleX(0.85);
}
.chk-filter-chips-icon i:last-child {
  transform: translate(0, 0) rotate(-90deg) scaleX(0.85);
}
.chk-filter-chips-text {
  position: relative;
}
.chk-filter-chips-chip:hover .chk-filter-chips-bg {
  border-color: var(--c);
}
.chk-filter-chips-chip:has(input:checked) {
  color: #fff;
}
.chk-filter-chips-chip input:checked + .chk-filter-chips-bg {
  background: var(--c);
  border-color: var(--c);
  animation: chk-filter-chips-press 0.35s ease-out;
}
.chk-filter-chips-chip input:checked ~ .chk-filter-chips-icon i:first-child {
  transform: translate(-0.18em, 0.11em) rotate(43deg) scaleX(0.4);
}
.chk-filter-chips-chip input:checked ~ .chk-filter-chips-icon i:last-child {
  transform: translate(0.11em, 0.01em) rotate(-47deg) scaleX(0.75);
}
.chk-filter-chips-chip input:focus-visible + .chk-filter-chips-bg {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-filter-chips-press {
  0% { transform: scale(1); }
  40% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .chk-filter-chips, .chk-filter-chips *, .chk-filter-chips::before, .chk-filter-chips::after, .chk-filter-chips *::before, .chk-filter-chips *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --chk-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --chk-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 24px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar checkboxes