AI CSS Animations

Yes No Radio Cards with Icons

A yes or no question answered with two cards. The chosen card lifts into a ring of its own color, its icon disc fills and the check or cross draws itself in with stroke-dashoffset.

Also known as: yes no radio buttons, yes no radio button cards, yes or no card selection css.

HTML

<div class="rad-yes-no-icon-cards" role="radiogroup" aria-label="Email me when the beta opens?">
  <p class="rad-yes-no-icon-cards-q" aria-hidden="true">Email me when the beta opens?</p>
  <div class="rad-yes-no-icon-cards-grid">
    <label class="rad-yes-no-icon-cards-yes">
      <input type="radio" name="rad-yes-no-icon-cards" value="yes">
      <span class="rad-yes-no-icon-cards-card">
        <span class="rad-yes-no-icon-cards-icon" aria-hidden="true"><svg viewBox="0 0 24 24"><path pathLength="1" d="M5 12.5l4.5 4.5L19 7.5"/></svg></span>
        <span class="rad-yes-no-icon-cards-dot" aria-hidden="true"></span>
        <span class="rad-yes-no-icon-cards-title">Yes, notify me</span>
        <span class="rad-yes-no-icon-cards-sub">One email, no spam</span>
      </span>
    </label>
    <label class="rad-yes-no-icon-cards-no">
      <input type="radio" name="rad-yes-no-icon-cards" value="no">
      <span class="rad-yes-no-icon-cards-card">
        <span class="rad-yes-no-icon-cards-icon" aria-hidden="true"><svg viewBox="0 0 24 24"><path pathLength="1" d="M7 7l10 10M17 7L7 17"/></svg></span>
        <span class="rad-yes-no-icon-cards-dot" aria-hidden="true"></span>
        <span class="rad-yes-no-icon-cards-title">No thanks</span>
        <span class="rad-yes-no-icon-cards-sub">Maybe later</span>
      </span>
    </label>
  </div>
</div>

CSS

.rad-yes-no-icon-cards {
  --c: var(--rad-color, #3b82f6);
  font-size: var(--rad-size, 18px);
  display: inline-grid;
  gap: 0.6em;
  font-family: system-ui, sans-serif;
  line-height: 1.2;
}
.rad-yes-no-icon-cards-q {
  margin: 0;
  font-weight: 600;
}
.rad-yes-no-icon-cards-grid {
  display: flex;
  gap: 0.6em;
}
.rad-yes-no-icon-cards label {
  position: relative;
  cursor: pointer;
}
.rad-yes-no-icon-cards-yes { --tone: var(--c); }
.rad-yes-no-icon-cards-no { --tone: #f43f5e; }
.rad-yes-no-icon-cards input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.rad-yes-no-icon-cards-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  row-gap: 0.2em;
  box-sizing: border-box;
  width: 8.8em;
  padding: 0.75em 0.8em 0.8em;
  border: 1px solid color-mix(in srgb, currentColor 14%, transparent);
  border-radius: 0.85em;
  background: color-mix(in srgb, currentColor 3%, transparent);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.3s ease;
}
.rad-yes-no-icon-cards label:hover .rad-yes-no-icon-cards-card {
  border-color: color-mix(in srgb, var(--tone) 50%, transparent);
}
.rad-yes-no-icon-cards-icon {
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  margin-bottom: 0.35em;
  border-radius: 50%;
  background: color-mix(in srgb, currentColor 8%, transparent);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
.rad-yes-no-icon-cards-icon svg {
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: color-mix(in srgb, currentColor 45%, transparent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  transition: stroke 0.25s ease;
}
.rad-yes-no-icon-cards-dot {
  box-sizing: border-box;
  width: 1em;
  height: 1em;
  border: 0.1em solid color-mix(in srgb, currentColor 28%, transparent);
  border-radius: 50%;
  transition: border-color 0.25s ease, box-shadow 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-yes-no-icon-cards-title {
  grid-column: 1 / -1;
  font-size: 0.9em;
  font-weight: 650;
}
.rad-yes-no-icon-cards-sub {
  grid-column: 1 / -1;
  font-size: 0.72em;
  color: color-mix(in srgb, currentColor 55%, transparent);
}
.rad-yes-no-icon-cards input:checked + .rad-yes-no-icon-cards-card {
  transform: translateY(-0.18em);
  border-color: var(--tone);
  background: color-mix(in srgb, var(--tone) 8%, transparent);
  box-shadow: 0 0 0 1px var(--tone), 0 0.7em 1.3em -0.8em var(--tone);
}
.rad-yes-no-icon-cards input:checked + .rad-yes-no-icon-cards-card .rad-yes-no-icon-cards-icon {
  background: var(--tone);
  box-shadow: 0 0.25em 0.6em -0.25em var(--tone);
  animation: rad-yes-no-icon-cards-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-yes-no-icon-cards input:checked + .rad-yes-no-icon-cards-card .rad-yes-no-icon-cards-icon svg {
  stroke: #fff;
  animation: rad-yes-no-icon-cards-draw 0.45s cubic-bezier(0.65, 0, 0.35, 1) 0.1s both;
}
.rad-yes-no-icon-cards input:checked + .rad-yes-no-icon-cards-card .rad-yes-no-icon-cards-dot {
  border-color: var(--tone);
  box-shadow: inset 0 0 0 0.2em var(--tone);
}
.rad-yes-no-icon-cards input:focus-visible + .rad-yes-no-icon-cards-card {
  outline: 0.12em solid var(--tone);
  outline-offset: 0.22em;
}
@keyframes rad-yes-no-icon-cards-pop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}
@keyframes rad-yes-no-icon-cards-draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .rad-yes-no-icon-cards *,
  .rad-yes-no-icon-cards *::before,
  .rad-yes-no-icon-cards *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rad-yes-no-icon-cards, .rad-yes-no-icon-cards *, .rad-yes-no-icon-cards::before, .rad-yes-no-icon-cards::after, .rad-yes-no-icon-cards *::before, .rad-yes-no-icon-cards *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --rad-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --rad-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • 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 radio buttons