A gradient ring that floods with the same gradient from one corner when checked, while the label picks up the gradient too. The ring is a masked pseudo-element; the fill is a growing clip-path circle.
Also known as: gradient border checkbox, colorful checkbox css.
<label class="chk-gradient-checkbox">
<input type="checkbox">
<span class="chk-gradient-checkbox-box">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
</span>
<span class="chk-gradient-checkbox-text">Early access</span>
</label>.chk-gradient-checkbox {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6em;
font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
line-height: 1.3;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
--c2: color-mix(in oklab, var(--c), #ec4899 65%);
--grad: linear-gradient(135deg, var(--c), var(--c2));
font-weight: 600;}
.chk-gradient-checkbox input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-gradient-checkbox-box {
position: relative;
display: grid;
place-items: center;
flex: none;
width: 1.375em;
height: 1.375em;
border-radius: 0.35em;
}
.chk-gradient-checkbox-box::before,
.chk-gradient-checkbox-box::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
background: var(--grad);
}
.chk-gradient-checkbox-box::before {
padding: 0.14em;
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
-webkit-mask-composite: xor;
mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.chk-gradient-checkbox-box::after {
clip-path: circle(0% at 0% 100%);
transition: clip-path 0.3s cubic-bezier(0.5, 0, 0.75, 0) 0.1s;
}
.chk-gradient-checkbox-box svg {
display: block;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
position: relative;
z-index: 1;
width: 0.9em;
height: 0.9em;
stroke: #fff;
stroke-width: 3;
stroke-dasharray: 22;
stroke-dashoffset: 22;
transition: stroke-dashoffset 0.12s ease-in;
}
.chk-gradient-checkbox-text {
background: var(--grad);
-webkit-background-clip: text;
background-clip: text;
color: currentColor;
transition: color 0.35s ease;
}
.chk-gradient-checkbox input:checked + .chk-gradient-checkbox-box::after {
clip-path: circle(142% at 0% 100%);
transition: clip-path 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.chk-gradient-checkbox input:checked + .chk-gradient-checkbox-box svg {
stroke-dashoffset: 0;
transition: stroke-dashoffset 0.28s ease-out 0.32s;
}
.chk-gradient-checkbox input:checked ~ .chk-gradient-checkbox-text {
color: transparent;
}
.chk-gradient-checkbox input:focus-visible + .chk-gradient-checkbox-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@media (prefers-reduced-motion: reduce) {
.chk-gradient-checkbox, .chk-gradient-checkbox *, .chk-gradient-checkbox::before, .chk-gradient-checkbox::after, .chk-gradient-checkbox *::before, .chk-gradient-checkbox *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--chk-color on the element or a parent.
Currently previewing #3b82f6.--chk-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.