AI CSS Animations

Image Radio Buttons

Picture tiles that replace the radio circle. Unpicked images wait in grayscale; the chosen one lifts into an accent ring, its image zooms and warms to full color and a check badge pops in.

Also known as: css radio button with image, replace radio button with image css, image picker radio.

HTML

<div class="rad-image-radio-buttons" role="radiogroup" aria-label="Destination">
  <label>
    <input type="radio" name="rad-image-radio-buttons" value="mountains" checked>
    <span class="rad-image-radio-buttons-pic">
      <svg class="rad-image-radio-buttons-scene" viewBox="0 0 60 40" preserveAspectRatio="xMidYMid slice" aria-hidden="true"><rect width="60" height="40" fill="#c7ddff"/><circle cx="45" cy="11" r="5" fill="#fde68a"/><path d="M-2 40L18 13l10 12 7-7 27 22z" fill="#7c8aa5"/><path d="M18 13l4.2 5.6-2.4-1-1.8 1.9-2-1.5-2.3 1.2z" fill="#fff"/><path d="M-2 40c10-8 18-10 28-6s18-6 36 0v6z" fill="#3f4b63"/></svg>
      <svg class="rad-image-radio-buttons-check" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
    </span>
    <span class="rad-image-radio-buttons-cap">Mountains</span>
  </label>
  <label>
    <input type="radio" name="rad-image-radio-buttons" value="beach">
    <span class="rad-image-radio-buttons-pic">
      <svg class="rad-image-radio-buttons-scene" viewBox="0 0 60 40" preserveAspectRatio="xMidYMid slice" aria-hidden="true"><rect width="60" height="40" fill="#fed7aa"/><circle cx="30" cy="23" r="8" fill="#fb923c"/><rect y="24" width="60" height="9" fill="#38bdf8"/><path d="M0 26.5h60" stroke="#e0f2fe" stroke-width="1" stroke-dasharray="6 5"/><path d="M0 31c14-3 30-3 60 1v8H0z" fill="#fde68a"/></svg>
      <svg class="rad-image-radio-buttons-check" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
    </span>
    <span class="rad-image-radio-buttons-cap">Beach</span>
  </label>
  <label>
    <input type="radio" name="rad-image-radio-buttons" value="city">
    <span class="rad-image-radio-buttons-pic">
      <svg class="rad-image-radio-buttons-scene" viewBox="0 0 60 40" preserveAspectRatio="xMidYMid slice" aria-hidden="true"><rect width="60" height="40" fill="#1e1b4b"/><circle cx="49" cy="9" r="4" fill="#f8fafc"/><path d="M4 18h9v22H4zM15 11h8v29h-8zM25 20h10v20H25zM37 14h8v26h-8zM47 22h10v18H47z" fill="#4338ca"/><path d="M7 22h2v2.5H7zM7 28h2v2.5H7zM18 15h2v2.5h-2zM18 21h2v2.5h-2zM28 24h2v2.5h-2zM40 18h2v2.5h-2zM40 26h2v2.5h-2zM50 26h2v2.5h-2z" fill="#fde68a"/></svg>
      <svg class="rad-image-radio-buttons-check" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
    </span>
    <span class="rad-image-radio-buttons-cap">City</span>
  </label>
</div>

CSS

.rad-image-radio-buttons {
  --c: var(--rad-color, #3b82f6);
  font-size: var(--rad-size, 18px);
  display: inline-flex;
  gap: 0.75em;
  font-family: system-ui, sans-serif;
  line-height: 1.2;
}
.rad-image-radio-buttons label {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.5em;
  cursor: pointer;
}
.rad-image-radio-buttons input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.rad-image-radio-buttons-pic {
  position: relative;
  display: block;
  width: 5.4em;
  height: 3.8em;
  overflow: hidden;
  border-radius: 0.7em;
  box-shadow: 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent);
  transition: box-shadow 0.3s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-image-radio-buttons-scene {
  display: block;
  width: 100%;
  height: 100%;
  filter: grayscale(0.9);
  transition: filter 0.45s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.rad-image-radio-buttons label:hover .rad-image-radio-buttons-scene {
  filter: grayscale(0.3);
}
.rad-image-radio-buttons-check {
  position: absolute;
  top: 0.3em;
  right: 0.3em;
  box-sizing: border-box;
  width: 1.15em;
  height: 1.15em;
  padding: 0.2em;
  border-radius: 50%;
  background: var(--c);
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: scale(0);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-image-radio-buttons-cap {
  font-size: 0.8em;
  font-weight: 600;
  color: color-mix(in srgb, currentColor 60%, transparent);
  transition: color 0.25s ease;
}
.rad-image-radio-buttons input:checked + .rad-image-radio-buttons-pic {
  box-shadow: 0 0 0 0.15em var(--c);
  transform: translateY(-0.15em);
}
.rad-image-radio-buttons input:checked + .rad-image-radio-buttons-pic .rad-image-radio-buttons-scene {
  filter: none;
  transform: scale(1.12);
}
.rad-image-radio-buttons input:checked + .rad-image-radio-buttons-pic .rad-image-radio-buttons-check {
  transform: scale(1);
  transition-delay: 0.1s;
}
.rad-image-radio-buttons input:checked ~ .rad-image-radio-buttons-cap {
  color: var(--c);
}
.rad-image-radio-buttons input:focus-visible + .rad-image-radio-buttons-pic {
  outline: 0.12em dashed var(--c);
  outline-offset: 0.3em;
}

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