A vertical radio list with one shared dot that travels between the rings, stretching mid-flight and squashing as it lands. :has() picks the row; a keyframe per row replays the squash.
Also known as: radio button list css, animated radio button css, moving dot radio.
<div class="rad-sliding-dot-radio" role="radiogroup" aria-label="Notifications"> <span class="rad-sliding-dot-radio-dot" aria-hidden="true"></span> <label><input type="radio" name="rad-sliding-dot-radio" value="all" checked><span>All activity</span></label> <label><input type="radio" name="rad-sliding-dot-radio" value="mentions"><span>Mentions only</span></label> <label><input type="radio" name="rad-sliding-dot-radio" value="none"><span>Nothing</span></label> </div>
.rad-sliding-dot-radio {
--c: var(--rad-color, #3b82f6);
font-size: var(--rad-size, 18px);
--i: 0;
position: relative;
display: grid;
gap: 0.6em;
font-family: system-ui, sans-serif;
line-height: 1.2;
}
.rad-sliding-dot-radio label {
position: relative;
display: flex;
align-items: center;
gap: 0.7em;
height: 1.6em;
cursor: pointer;
}
.rad-sliding-dot-radio label::before {
content: "";
flex: none;
box-sizing: border-box;
width: 1.3em;
height: 1.3em;
border: 0.12em solid color-mix(in srgb, currentColor 30%, transparent);
border-radius: 50%;
transition: border-color 0.3s ease;
}
.rad-sliding-dot-radio label:hover::before {
border-color: color-mix(in srgb, var(--c) 60%, transparent);
}
.rad-sliding-dot-radio label:has(:checked)::before {
border-color: var(--c);
}
.rad-sliding-dot-radio input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.rad-sliding-dot-radio input + span {
color: color-mix(in srgb, currentColor 65%, transparent);
transition: color 0.3s ease;
}
.rad-sliding-dot-radio input:checked + span {
color: currentColor;
}
.rad-sliding-dot-radio input:focus-visible + span {
outline: 0.12em solid var(--c);
outline-offset: 0.2em;
border-radius: 0.2em;
}
.rad-sliding-dot-radio-dot {
position: absolute;
top: 0.5em;
left: 0.35em;
width: 0.6em;
height: 0.6em;
border-radius: 50%;
background: var(--c);
translate: 0 calc(var(--i) * 2.2em);
transition: translate 0.5s cubic-bezier(0.6, -0.3, 0.3, 1.3), scale 0.2s ease;
animation: rad-sliding-dot-radio-hop-a 0.5s ease;
}
.rad-sliding-dot-radio:has(label:nth-of-type(2) :checked) { --i: 1; }
.rad-sliding-dot-radio:has(label:nth-of-type(3) :checked) { --i: 2; }
.rad-sliding-dot-radio:has(label:nth-of-type(2) :checked) .rad-sliding-dot-radio-dot { animation-name: rad-sliding-dot-radio-hop-b; }
.rad-sliding-dot-radio:has(label:nth-of-type(3) :checked) .rad-sliding-dot-radio-dot { animation-name: rad-sliding-dot-radio-hop-c; }
.rad-sliding-dot-radio:not(:has(:checked)) .rad-sliding-dot-radio-dot { scale: 0; }
/* Three identical keyframes: a new name restarts the squash on every change. */
@keyframes rad-sliding-dot-radio-hop-a {
0%, 100% { transform: scale(1); }
35% { transform: scale(0.75, 1.5); }
70% { transform: scale(1.25, 0.8); }
}
@keyframes rad-sliding-dot-radio-hop-b {
0%, 100% { transform: scale(1); }
35% { transform: scale(0.75, 1.5); }
70% { transform: scale(1.25, 0.8); }
}
@keyframes rad-sliding-dot-radio-hop-c {
0%, 100% { transform: scale(1); }
35% { transform: scale(0.75, 1.5); }
70% { transform: scale(1.25, 0.8); }
}
@media (prefers-reduced-motion: reduce) {
.rad-sliding-dot-radio, .rad-sliding-dot-radio *, .rad-sliding-dot-radio::before, .rad-sliding-dot-radio::after, .rad-sliding-dot-radio *::before, .rad-sliding-dot-radio *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--rad-color on the element or a parent.
Currently previewing #3b82f6.--rad-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 18px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.