AI CSS Animations

Checkbox Card Select

The whole card is the label: selecting it turns the border and icon tile to the accent, adds a soft ring and pops a check badge into the corner. Good for plan features, integrations and settings.

Also known as: checkbox card css, selectable card css, card checkbox.

HTML

<label class="chk-card-select">
  <input type="checkbox">
  <span class="chk-card-select-frame"></span>
  <span class="chk-card-select-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 18.5h10.3a4 4 0 0 0 .6-7.95 6 6 0 0 0-11.5-1.4A4.7 4.7 0 0 0 7 18.5z"/></svg></span>
  <span class="chk-card-select-text">
    <span class="chk-card-select-title">Cloud backup</span>
    <span class="chk-card-select-sub">Daily, kept 30 days</span>
  </span>
  <span class="chk-card-select-badge"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6.5 12.5l3.5 3.5 7.5-7.5"/></svg></span>
</label>

CSS

.chk-card-select {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75em;
  width: 14.5em;
  padding: 0.85em 0.9em 0.85em 0.85em;
  line-height: 1.25;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;}
.chk-card-select input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-card-select-frame {
  position: absolute;
  inset: 0;
  border: 0.08em solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: 0.9em;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 0%, transparent);
  transition: border-color 0.25s ease, box-shadow 0.3s ease, background-color 0.25s ease;
}
.chk-card-select-icon {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 2.2em;
  height: 2.2em;
  border-radius: 0.6em;
  background: color-mix(in srgb, currentColor 8%, transparent);
  transition: background-color 0.3s ease, color 0.3s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-card-select-icon svg {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.chk-card-select-text {
  position: relative;
  display: grid;
  flex: 1;
}
.chk-card-select-title {
  font-weight: 600;
}
.chk-card-select-sub {
  font-size: 0.72em;
  opacity: 0.6;
}
.chk-card-select-badge {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.2em;
  height: 1.2em;
  border: 0.1em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 50%;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.chk-card-select-badge svg {
  width: 0.9em;
  height: 0.9em;
  fill: none;
  stroke: #fff;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 17;
  stroke-dashoffset: 17;
  transition: stroke-dashoffset 0.15s ease-in;
}
.chk-card-select:hover .chk-card-select-frame {
  border-color: color-mix(in srgb, var(--c) 55%, transparent);
}
.chk-card-select input:checked + .chk-card-select-frame {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 6%, transparent);
  box-shadow: 0 0 0 0.22em color-mix(in srgb, var(--c) 22%, transparent);
}
.chk-card-select input:checked ~ .chk-card-select-icon {
  background: var(--c);
  color: #fff;
  transform: rotate(-8deg) scale(1.06);
}
.chk-card-select input:checked ~ .chk-card-select-badge {
  background: var(--c);
  border-color: var(--c);
  animation: chk-card-select-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-card-select input:checked ~ .chk-card-select-badge svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s ease-out 0.15s;
}
.chk-card-select input:focus-visible + .chk-card-select-frame {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-card-select-pop {
  0% { transform: scale(0.4); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .chk-card-select, .chk-card-select *, .chk-card-select::before, .chk-card-select::after, .chk-card-select *::before, .chk-card-select *::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.

<label class="relative flex w-72 cursor-pointer select-none items-center gap-3 rounded-2xl border border-gray-300 p-4 transition duration-300 has-[:checked]:border-blue-500 has-[:checked]:bg-blue-500/5 has-[:checked]:ring-4 has-[:checked]:ring-blue-500/20 has-[:focus-visible]:outline has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-blue-500">
  <input type="checkbox" class="peer sr-only">
  <span class="grid h-10 w-10 shrink-0 place-items-center rounded-xl bg-gray-100 text-gray-600 transition duration-300 peer-checked:-rotate-6 peer-checked:bg-blue-500 peer-checked:text-white">
    <svg viewBox="0 0 24 24" class="h-5 w-5 fill-none stroke-current stroke-2" aria-hidden="true"><path d="M7 18.5h10.3a4 4 0 0 0 .6-7.95 6 6 0 0 0-11.5-1.4A4.7 4.7 0 0 0 7 18.5z"/></svg>
  </span>
  <span class="grid flex-1"><span class="font-semibold">Cloud backup</span><span class="text-sm text-gray-500">Daily, kept 30 days</span></span>
  <span class="grid h-5 w-5 scale-75 place-items-center rounded-full border-2 border-gray-300 text-transparent transition duration-300 peer-checked:scale-100 peer-checked:border-blue-500 peer-checked:bg-blue-500 peer-checked:text-white">
    <svg viewBox="0 0 24 24" class="h-3.5 w-3.5 fill-none stroke-current stroke-[3.4]" aria-hidden="true"><path d="M6.5 12.5l3.5 3.5 7.5-7.5"/></svg>
  </span>
</label>

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