A checkout stepper where hovering a later step previews the progress line reaching it, in a lighter tint than the real progress. A clip-path inset on the line is set per step with :has().
Also known as: step indicator hover, multi step progress bar css, checkout steps hover.
<ol class="hfx-stepper-preview"> <li><a href="#"><span><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg></span>Cart</a></li> <li aria-current="step"><a href="#"><span>2</span>Details</a></li> <li><a href="#"><span>3</span>Shipping</a></li> <li><a href="#"><span>4</span>Payment</a></li> </ol>
.hfx-stepper-preview {
--c: var(--hfx-color, #3b82f6);
--p: 33.33%;
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
grid-template-columns: repeat(4, 5.6em);
margin: 0;
padding: 0;
list-style: none;
font-family: system-ui, sans-serif;
}
/* track, then the progress line clipped to the current or hovered step */
.hfx-stepper-preview::before,
.hfx-stepper-preview::after {
content: "";
position: absolute;
top: 0.95em;
left: 2.8em;
right: 2.8em;
height: 0.2em;
border-radius: 0.1em;
background: color-mix(in srgb, var(--c) 18%, transparent);
}
.hfx-stepper-preview::after {
background: linear-gradient(90deg, var(--c) 33.33%, color-mix(in srgb, var(--c) 50%, transparent) 33.33%);
clip-path: inset(0 calc(100% - var(--p)) 0 0);
transition: clip-path 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-stepper-preview a {
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.45em;
color: color-mix(in srgb, currentColor 60%, transparent);
font-size: 0.85em;
font-weight: 600;
text-decoration: none;
transition: color 0.25s ease;
}
.hfx-stepper-preview span {
display: grid;
place-items: center;
width: 2.35em;
height: 2.35em;
border: 2px solid color-mix(in srgb, var(--c) 30%, transparent);
border-radius: 50%;
background: color-mix(in srgb, var(--c) 8%, #fff);
color: #6b7280;
transition: border-color 0.25s ease, color 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-stepper-preview svg { width: 1.2em; height: 1.2em; }
/* steps between the current one and the hovered one pick up a tint */
.hfx-stepper-preview :where(li:has(~ li a:is(:hover, :focus-visible))) span { border-color: color-mix(in srgb, var(--c) 60%, transparent); }
.hfx-stepper-preview li[aria-current] a { color: var(--c); }
.hfx-stepper-preview li[aria-current] span {
border-color: var(--c);
color: var(--c);
}
.hfx-stepper-preview a:is(:hover, :focus-visible) { color: var(--c); }
.hfx-stepper-preview a:is(:hover, :focus-visible) span {
border-color: var(--c);
color: var(--c);
transform: scale(1.12);
}
.hfx-stepper-preview li:first-child span {
border-color: var(--c);
background: var(--c);
color: #fff;
}
.hfx-stepper-preview:has(li:nth-child(1) a:is(:hover, :focus-visible)) { --p: 0%; }
.hfx-stepper-preview:has(li:nth-child(3) a:is(:hover, :focus-visible)) { --p: 66.67%; }
.hfx-stepper-preview:has(li:nth-child(4) a:is(:hover, :focus-visible)) { --p: 100%; }
@media (prefers-reduced-motion: reduce) {
.hfx-stepper-preview, .hfx-stepper-preview *, .hfx-stepper-preview::before, .hfx-stepper-preview::after, .hfx-stepper-preview *::before, .hfx-stepper-preview *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.