AI CSS Animations

Payment Method Radio Buttons

Icon tiles for choosing how to pay: card, bank or wallet. The chosen tile gets an accent border, its corner ring thickens into a filled radio and its icon gives a small nudge.

Also known as: payment method selector css, radio button with icon css, checkout payment options.

HTML

<div class="rad-payment-method-tiles" role="radiogroup" aria-label="Payment method">
  <label>
    <input type="radio" name="rad-payment-method-tiles" value="card" checked>
    <span class="rad-payment-method-tiles-tile"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="2.5" y="5" width="19" height="14" rx="2.5"/><path d="M2.5 9.5h19M6 15h4"/></svg>Card</span>
  </label>
  <label>
    <input type="radio" name="rad-payment-method-tiles" value="bank">
    <span class="rad-payment-method-tiles-tile"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 9.5L12 4l9 5.5M5.5 10.5v7M10 10.5v7M14 10.5v7M18.5 10.5v7M3 20h18"/></svg>Bank</span>
  </label>
  <label>
    <input type="radio" name="rad-payment-method-tiles" value="wallet">
    <span class="rad-payment-method-tiles-tile"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 7.5V7a2 2 0 0 1 2-2h10v2.5"/><rect x="3" y="7.5" width="18" height="12" rx="2.5"/><path d="M15.5 13.5h2"/></svg>Wallet</span>
  </label>
</div>

CSS

.rad-payment-method-tiles {
  --c: var(--rad-color, #3b82f6);
  font-size: var(--rad-size, 18px);
  display: inline-flex;
  gap: 0.6em;
  font-weight: 600;
  font-family: system-ui, sans-serif;
  line-height: 1.2;
}
.rad-payment-method-tiles label {
  position: relative;
  cursor: pointer;
}
.rad-payment-method-tiles input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.rad-payment-method-tiles-tile {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.4em;
  box-sizing: border-box;
  width: 6.4em;
  padding: 1.1em 0 0.8em;
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
  border-radius: 0.9em;
  font-size: 0.85em;
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.rad-payment-method-tiles-tile::after {
  content: "";
  position: absolute;
  top: 0.6em;
  right: 0.6em;
  width: 0.95em;
  height: 0.95em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.13em color-mix(in srgb, currentColor 28%, transparent);
  transition: box-shadow 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-payment-method-tiles-tile svg {
  display: block;
  width: 2.1em;
  height: 2.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: color-mix(in srgb, currentColor 55%, transparent);
  transition: color 0.25s ease;
}
.rad-payment-method-tiles label:hover .rad-payment-method-tiles-tile {
  border-color: color-mix(in srgb, var(--c) 55%, transparent);
}
.rad-payment-method-tiles input:checked + .rad-payment-method-tiles-tile {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 8%, transparent);
  box-shadow: 0 0 0 1px var(--c);
}
.rad-payment-method-tiles input:checked + .rad-payment-method-tiles-tile::after {
  box-shadow: inset 0 0 0 0.32em var(--c);
}
.rad-payment-method-tiles input:checked + .rad-payment-method-tiles-tile svg {
  color: var(--c);
  animation: rad-payment-method-tiles-nudge 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-payment-method-tiles input:focus-visible + .rad-payment-method-tiles-tile {
  outline: 0.14em solid var(--c);
  outline-offset: 0.22em;
}
@keyframes rad-payment-method-tiles-nudge {
  0% { transform: none; }
  35% { transform: translateY(-0.18em) rotate(-8deg); }
  70% { transform: rotate(4deg); }
  100% { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rad-payment-method-tiles, .rad-payment-method-tiles *, .rad-payment-method-tiles::before, .rad-payment-method-tiles::after, .rad-payment-method-tiles *::before, .rad-payment-method-tiles *::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