Back to CSS Radio Buttons Gradient Border Pure CSS
Share
HTML
<fieldset class="crb-grad">
  <legend class="crb-sr">Tier</legend>
  <label><input type="radio" name="crb-grad" /><span class="crb-grad-card">Bronze</span></label>
  <label><input type="radio" name="crb-grad" /><span class="crb-grad-card">Silver</span></label>
  <label
    ><input type="radio" name="crb-grad" checked /><span class="crb-grad-card">Gold</span></label
  >
</fieldset>
CSS
.crb-grad { display: flex; gap: 8px; border: 0; padding: 0; }
.crb-grad input { appearance: none; -webkit-appearance: none; position: absolute; opacity: 0; }
.crb-grad label { cursor: pointer; }
.crb-grad-card {
  display: block; padding: 10px 18px;
  background: #1a1a28; border-radius: 8px;
  font: 600 12px/1 system-ui, sans-serif; color: #b8b6d4;
  position: relative; isolation: isolate;
  transition: color 0.25s;
}
.crb-grad-card::before {
  content: ''; position: absolute; inset: -2px; border-radius: 10px;
  background: conic-gradient(from 0deg, #7c6cff, #ff6c8a, #f5a623, #2ecc8a, #06b6d4, #7c6cff);
  z-index: -1; opacity: 0;
  animation: crb-grad-spin 4s linear infinite;
  transition: opacity 0.3s;
}
.crb-grad-card::after {
  content: ''; position: absolute; inset: 0; border-radius: 8px;
  background: #1a1a28; z-index: -1;
}
.crb-grad input:checked + .crb-grad-card { color: #fff; }
.crb-grad input:checked + .crb-grad-card::before { opacity: 1; }
@keyframes crb-grad-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .crb-grad,
  .crb-grad * {
    animation: none !important;
  }
}

.crb-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}