Back to CSS Radio Buttons Color Swatches Pure CSS
Share
HTML
<fieldset class="crb-swatch">
  <legend class="crb-sr">Colour</legend>
  <label style="--c: #7c6cff"><input type="radio" name="crb-swatch" /><span></span></label>
  <label style="--c: #ff6c8a"><input type="radio" name="crb-swatch" checked /><span></span></label>
  <label style="--c: #2ecc8a"><input type="radio" name="crb-swatch" /><span></span></label>
  <label style="--c: #f5a623"><input type="radio" name="crb-swatch" /><span></span></label>
  <label style="--c: #06b6d4"><input type="radio" name="crb-swatch" /><span></span></label>
</fieldset>
CSS
.crb-swatch { display: flex; gap: 10px; border: 0; padding: 0; }
.crb-swatch input { appearance: none; -webkit-appearance: none; position: absolute; opacity: 0; }
.crb-swatch label { cursor: pointer; }
.crb-swatch span {
  display: block;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 0 #15151d, 0 0 0 0 var(--c);
  transition: box-shadow 0.3s, transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.crb-swatch label:hover span { transform: scale(1.08); }
.crb-swatch input:checked + span {
  box-shadow: inset 0 0 0 4px #15151d, 0 0 0 2px var(--c), 0 0 16px var(--c);
  transform: scale(1.12);
}

.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;
}