Layout · 14 of 23
Stepper
Progress flow animation
<div class="stepper">
<div class="step active">1</div>
<div class="step-line"></div>
<div class="step">2</div>
<div class="step-line"></div>
<div class="step">3</div>
</div>
.stepper {
display: flex;
align-items: center;
width: 100%;
max-width: 320px;
justify-content: space-between;
cursor: pointer;
color: #f0f0f5;
}
.step {
width: 30px;
height: 30px;
border-radius: 50%;
background: #222;
border: 2px solid #444;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
transition: all 0.4s;
}
.step.active {
border-color: #7c5cff;
color: #7c5cff;
background: rgba(124, 92, 255, 0.1);
}
/* Connector line fills left-to-right when the step before it activates */
.step-line {
flex: 1;
height: 2px;
background: #333;
margin: 0 0.5rem;
position: relative;
overflow: hidden;
}
.step-line::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #7c5cff;
transform: translateX(-100%);
transition: transform 0.5s ease-out;
}
.step.active + .step-line::after {
transform: translateX(0);
}
// Click anywhere in the stepper to advance (wraps back to step 1)
var stepper = document.querySelector('.stepper');
var steps = stepper.querySelectorAll('.step');
var activeStep = 0;
stepper.addEventListener('click', function () {
activeStep = (activeStep + 1) % steps.length;
steps.forEach(function (s, i) {
s.classList.toggle('active', i <= activeStep);
});
});