A slider driven by its dots: each dot is a radio, the track glides to its slide and the caption rises in after it lands, while the active dot stretches into a pill. No script.
Also known as: pure css slider radio buttons, css carousel without javascript, carousel dots css.
<div class="rad-radio-carousel" role="radiogroup" aria-label="Slides">
<div class="rad-radio-carousel-view">
<div class="rad-radio-carousel-track">
<div class="rad-radio-carousel-slide"><b>01</b><span>Plan the trip</span></div>
<div class="rad-radio-carousel-slide"><b>02</b><span>Pack light</span></div>
<div class="rad-radio-carousel-slide"><b>03</b><span>Go</span></div>
</div>
</div>
<div class="rad-radio-carousel-dots">
<label><input type="radio" name="rad-radio-carousel" value="1" aria-label="Slide 1" checked></label>
<label><input type="radio" name="rad-radio-carousel" value="2" aria-label="Slide 2"></label>
<label><input type="radio" name="rad-radio-carousel" value="3" aria-label="Slide 3"></label>
</div>
</div>.rad-radio-carousel {
--c: var(--rad-color, #3b82f6);
font-size: var(--rad-size, 18px);
--i: 0;
display: grid;
justify-items: center;
gap: 0.7em;
font-family: system-ui, sans-serif;
line-height: 1.2;
}
.rad-radio-carousel:has(label:nth-of-type(2) :checked) { --i: 1; }
.rad-radio-carousel:has(label:nth-of-type(3) :checked) { --i: 2; }
.rad-radio-carousel-view {
width: 15em;
height: 5.6em;
overflow: hidden;
border-radius: 0.9em;
box-shadow: 0 0.5em 1.2em -0.7em color-mix(in srgb, var(--c) 80%, transparent);
}
.rad-radio-carousel-track {
display: flex;
height: 100%;
transform: translateX(calc(var(--i) * -15em));
transition: transform 0.6s cubic-bezier(0.77, 0, 0.18, 1);
}
.rad-radio-carousel-slide {
display: flex;
flex: none;
flex-direction: column;
justify-content: flex-end;
gap: 0.15em;
box-sizing: border-box;
width: 15em;
padding: 0.9em 1.1em;
color: #fff;
}
.rad-radio-carousel-slide:nth-child(1) { background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 45%, #0f172a)); }
.rad-radio-carousel-slide:nth-child(2) { background: linear-gradient(135deg, color-mix(in srgb, var(--c) 40%, #ec4899), color-mix(in srgb, var(--c) 35%, #6d28d9)); }
.rad-radio-carousel-slide:nth-child(3) { background: linear-gradient(135deg, color-mix(in srgb, var(--c) 40%, #14b8a6), color-mix(in srgb, var(--c) 40%, #0f172a)); }
.rad-radio-carousel-slide b {
font-size: 0.7em;
letter-spacing: 0.12em;
color: rgba(255, 255, 255, 0.75);
}
.rad-radio-carousel-slide span {
font-size: 1.25em;
font-weight: 700;
}
.rad-radio-carousel-slide :is(b, span) {
opacity: 0;
transform: translateY(0.6em);
transition: opacity 0.2s ease, transform 0.2s ease;
}
.rad-radio-carousel:has(label:nth-of-type(1) :checked) .rad-radio-carousel-slide:nth-child(1) :is(b, span),
.rad-radio-carousel:has(label:nth-of-type(2) :checked) .rad-radio-carousel-slide:nth-child(2) :is(b, span),
.rad-radio-carousel:has(label:nth-of-type(3) :checked) .rad-radio-carousel-slide:nth-child(3) :is(b, span) {
opacity: 1;
transform: none;
transition: opacity 0.4s ease 0.35s, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.35s;
}
.rad-radio-carousel:has(label:nth-of-type(1) :checked) .rad-radio-carousel-slide:nth-child(1) span,
.rad-radio-carousel:has(label:nth-of-type(2) :checked) .rad-radio-carousel-slide:nth-child(2) span,
.rad-radio-carousel:has(label:nth-of-type(3) :checked) .rad-radio-carousel-slide:nth-child(3) span {
transition-delay: 0.43s;
}
.rad-radio-carousel-dots {
display: flex;
}
.rad-radio-carousel-dots label {
position: relative;
padding: 0.35em 0.22em;
cursor: pointer;
}
.rad-radio-carousel-dots label::before {
content: "";
display: block;
width: 0.55em;
height: 0.55em;
border-radius: 0.3em;
background: color-mix(in srgb, currentColor 25%, transparent);
transition: width 0.45s cubic-bezier(0.65, 0, 0.35, 1), background-color 0.3s ease;
}
.rad-radio-carousel-dots label:hover::before {
background: color-mix(in srgb, currentColor 45%, transparent);
}
.rad-radio-carousel-dots label:has(:checked)::before {
width: 1.6em;
background: var(--c);
}
.rad-radio-carousel-dots label:has(:focus-visible)::before {
outline: 0.12em solid var(--c);
outline-offset: 0.15em;
}
.rad-radio-carousel-dots input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
@media (prefers-reduced-motion: reduce) {
.rad-radio-carousel, .rad-radio-carousel *, .rad-radio-carousel::before, .rad-radio-carousel::after, .rad-radio-carousel *::before, .rad-radio-carousel *::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.