AI CSS Animations

Glass Filter Chips

Frosted topic chips on a glass panel: pick one and it tints with the accent while a check draws in, and a CSS counter keeps the selected total. Real checkboxes and :has() for the state, no script.

Also known as: glassmorphism badge css, glass pill tags css, glass chip css.

Filter by topic

selected Show results

HTML

<div class="gls-glass-filter-chips">
  <span class="gls-glass-filter-chips-orb gls-glass-filter-chips-orb-a" aria-hidden="true"></span>
  <span class="gls-glass-filter-chips-orb gls-glass-filter-chips-orb-b" aria-hidden="true"></span>
  <div class="gls-glass-filter-chips-panel" role="group" aria-label="Filter by topic">
    <p class="gls-glass-filter-chips-title">Filter by topic</p>
    <div class="gls-glass-filter-chips-list">
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="design" checked><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Design</label>
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="motion"><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Motion</label>
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="css"><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>CSS</label>
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="glass" checked><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Glass</label>
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="tailwind"><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Tailwind</label>
      <label class="gls-glass-filter-chips-chip"><input type="checkbox" name="gls-glass-filter-chips-topic" value="icons"><svg class="gls-glass-filter-chips-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Icons</label>
    </div>
    <div class="gls-glass-filter-chips-foot">
      <span class="gls-glass-filter-chips-count">selected</span>
      <a class="gls-glass-filter-chips-apply" href="#">Show results</a>
    </div>
  </div>
</div>

CSS

.gls-glass-filter-chips {
  --c: var(--gls-color, #3b82f6);
  font-size: var(--gls-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 22em;
  height: 12em;
  border-radius: 1.25em;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 50%, #0c4a6e), color-mix(in srgb, var(--c) 30%, #1e1b4b));
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
}
.gls-glass-filter-chips-orb {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
}
.gls-glass-filter-chips-orb-a {
  right: 3em;
  top: 0.4em;
  width: 6.2em;
  height: 6.2em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 40%, #fff), var(--c));
  animation: gls-glass-filter-chips-drift-a 8s ease-in-out infinite alternate;
}
.gls-glass-filter-chips-orb-b {
  left: 3em;
  bottom: 0.3em;
  width: 5.4em;
  height: 5.4em;
  background: linear-gradient(135deg, #fdba74, #ec4899);
  animation: gls-glass-filter-chips-drift-b 10s ease-in-out infinite alternate;
}
.gls-glass-filter-chips-panel {
  width: 15.5em;
  padding: 0.85em 0.95em 0.75em;
  border-radius: 1.2em;
  counter-reset: gls-glass-filter-chips-n;
  background: color-mix(in srgb, #fff 16%, transparent);
  -webkit-backdrop-filter: blur(0.9em) saturate(1.5);
  backdrop-filter: blur(0.9em) saturate(1.5);
  border: 1px solid color-mix(in srgb, #fff 45%, transparent);
  box-shadow: 0 0.5em 1.5em -0.5em rgb(0 0 0 / 0.35), inset 0 1px 0 color-mix(in srgb, #fff 55%, transparent);
}
.gls-glass-filter-chips-title {
  margin: 0 0 0.65em;
  font-size: 0.72em;
  font-weight: 700;
}
.gls-glass-filter-chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
}
.gls-glass-filter-chips-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0.5em 0.85em;
  border: 1px solid rgb(255 255 255 / 0.32);
  border-radius: 99em;
  background-color: rgb(255 255 255 / 0.1);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.3);
  font-size: 0.64em;
  font-weight: 600;
  cursor: pointer;
  transition: translate 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.gls-glass-filter-chips-chip input {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.gls-glass-filter-chips-chip input:checked { counter-increment: gls-glass-filter-chips-n; }
.gls-glass-filter-chips-chip:hover {
  translate: 0 -0.15em;
  background-color: rgb(255 255 255 / 0.2);
}
.gls-glass-filter-chips-chip:has(input:checked) {
  border-color: rgb(255 255 255 / 0.55);
  background-color: color-mix(in srgb, var(--c) 72%, transparent);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.45), 0 0.35em 0.9em -0.35em var(--c);
}
.gls-glass-filter-chips-chip:has(input:focus-visible) { outline: 2px solid #fff; outline-offset: 0.15em; }
.gls-glass-filter-chips-check {
  width: 0;
  height: 1em;
  margin-right: 0;
  opacity: 0;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), margin 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, stroke-dashoffset 0.35s ease 0.1s;
}
.gls-glass-filter-chips-chip:has(input:checked) .gls-glass-filter-chips-check {
  width: 1em;
  margin-right: 0.35em;
  opacity: 1;
  stroke-dashoffset: 0;
}
.gls-glass-filter-chips-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75em;
  padding-top: 0.6em;
  border-top: 1px solid rgb(255 255 255 / 0.2);
}
.gls-glass-filter-chips-count { font-size: 0.62em; color: rgb(255 255 255 / 0.8); }
.gls-glass-filter-chips-count::before {
  content: counter(gls-glass-filter-chips-n) " ";
  color: #fff;
  font-weight: 700;
}
.gls-glass-filter-chips-apply {
  padding: 0.5em 1em;
  border-radius: 99em;
  background: #fff;
  color: color-mix(in srgb, var(--c) 60%, #0f172a);
  font-size: 0.62em;
  font-weight: 700;
  text-decoration: none;
  transition: scale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gls-glass-filter-chips-apply:hover { scale: 1.05; }
.gls-glass-filter-chips-apply:focus-visible { outline: 2px solid #fff; outline-offset: 0.15em; }
@keyframes gls-glass-filter-chips-drift-a {
  to { transform: translate(-4em, 2em) scale(1.1); }
}
@keyframes gls-glass-filter-chips-drift-b {
  to { transform: translate(4.5em, -1.5em) scale(0.9); }
}

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

Customizing this snippet

  • Color: set --gls-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --gls-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 glass effects