AI CSS Animations

Checkbox List Group

A bordered list where each row is a checkbox: a checkmark draws in on the right, the row tints and an accent bar grows on its left edge. The settings-screen pattern, with the real inputs kept.

Also known as: css checkbox list, list group checkbox, settings list checkmark.

HTML

<div class="chk-checkbox-list-group" role="group" aria-label="Notify me by">
  <label class="chk-checkbox-list-group-row"><input type="checkbox" checked><span class="chk-checkbox-list-group-tint"></span><span class="chk-checkbox-list-group-text">Email</span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></label>
  <label class="chk-checkbox-list-group-row"><input type="checkbox"><span class="chk-checkbox-list-group-tint"></span><span class="chk-checkbox-list-group-text">Push notifications</span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></label>
  <label class="chk-checkbox-list-group-row"><input type="checkbox"><span class="chk-checkbox-list-group-tint"></span><span class="chk-checkbox-list-group-text">Text message</span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></label>
</div>

CSS

.chk-checkbox-list-group {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  display: grid;
  width: 12em;
  border: 0.07em solid color-mix(in srgb, currentColor 16%, transparent);
  border-radius: 0.75em;
  overflow: hidden;
  line-height: 1.3;}
.chk-checkbox-list-group-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8em;
  padding: 0.55em 0.8em 0.55em 0.95em;
  font-size: 0.9em;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.chk-checkbox-list-group-row + .chk-checkbox-list-group-row {
  border-top: 0.07em solid color-mix(in srgb, currentColor 12%, transparent);
}
.chk-checkbox-list-group-row input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-checkbox-list-group-tint {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--c) 10%, transparent);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.chk-checkbox-list-group-tint::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0.2em;
  background: var(--c);
  transform: scaleY(0);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-checkbox-list-group-text {
  position: relative;
  transition: color 0.2s ease;
}
.chk-checkbox-list-group-row svg {
  position: relative;
  flex: none;
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: var(--c);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset 0.15s ease-in;
}
.chk-checkbox-list-group-row:hover .chk-checkbox-list-group-tint {
  opacity: 0.5;
}
.chk-checkbox-list-group-row input:checked + .chk-checkbox-list-group-tint {
  opacity: 1;
}
.chk-checkbox-list-group-row input:checked + .chk-checkbox-list-group-tint::before {
  transform: scaleY(1);
}
.chk-checkbox-list-group-row input:checked ~ .chk-checkbox-list-group-text {
  color: var(--c);
}
.chk-checkbox-list-group-row input:checked ~ svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s cubic-bezier(0.65, 0, 0.35, 1) 0.05s;
}
.chk-checkbox-list-group-row input:focus-visible + .chk-checkbox-list-group-tint {
  outline: 0.12em solid var(--c);
  outline-offset: -0.12em;
}

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

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<div class="w-56 divide-y divide-gray-200 overflow-hidden rounded-xl border border-gray-200">
  <label class="relative flex cursor-pointer select-none items-center justify-between px-4 py-2.5 transition-colors has-[:checked]:bg-blue-500/10 has-[:checked]:text-blue-600 has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-inset has-[:focus-visible]:ring-blue-500">
    <input type="checkbox" class="peer sr-only" checked>
    <span>Email</span>
    <svg viewBox="0 0 24 24" class="h-5 w-5 fill-none stroke-blue-500 stroke-[3] transition-[stroke-dashoffset] duration-300 [stroke-dasharray:20] [stroke-dashoffset:20] [stroke-linecap:round] [stroke-linejoin:round] peer-checked:[stroke-dashoffset:0]" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
  </label>
  <label class="relative flex cursor-pointer select-none items-center justify-between px-4 py-2.5 transition-colors has-[:checked]:bg-blue-500/10 has-[:checked]:text-blue-600 has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-inset has-[:focus-visible]:ring-blue-500">
    <input type="checkbox" class="peer sr-only">
    <span>Push notifications</span>
    <svg viewBox="0 0 24 24" class="h-5 w-5 fill-none stroke-blue-500 stroke-[3] transition-[stroke-dashoffset] duration-300 [stroke-dasharray:20] [stroke-dashoffset:20] [stroke-linecap:round] [stroke-linejoin:round] peer-checked:[stroke-dashoffset:0]" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
  </label>
</div>

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