The 'Resend code' button of sign-in flows: click and it locks for a few seconds with a live countdown and a draining bar, then frees itself. Only :active plus long transitions on a registered number.
Also known as: resend otp button css, cooldown button css, resend code timer.
<div class="btn-resend-cooldown"> <button class="btn-resend-cooldown-btn" type="button">Resend code</button> <span class="btn-resend-cooldown-wait" aria-hidden="true"></span> </div>
@property --btn-resend-cooldown-n {
syntax: "<number>";
inherits: false;
initial-value: 0;
}
.btn-resend-cooldown {
--c: var(--btn-color, #3b82f6);
position: relative;
display: inline-grid;
font-size: var(--btn-size, 18px);
}
.btn-resend-cooldown-btn {
--c: var(--btn-color, #3b82f6);
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: 0.75em 1.6em;
border: 0;
border-radius: 0.6em;
font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
width: 11em;
padding: 0.8em 1em;
background: var(--c);
color: #fff;
box-shadow: 0 0.4em 1em -0.4em var(--c);
font-size: 1em;
transition: transform 0.2s ease;}
.btn-resend-cooldown-btn:focus-visible {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
.btn-resend-cooldown-wait {
position: absolute;
inset: 0;
overflow: hidden;
display: grid;
place-items: center;
border-radius: 0.6em;
background: color-mix(in srgb, var(--c) 12%, #eef1f5);
color: color-mix(in srgb, var(--c) 45%, #64748b);
font: 600 1em/1.1 system-ui, sans-serif;
font-variant-numeric: tabular-nums;
cursor: not-allowed;
counter-reset: btn-resend-cooldown-n calc(var(--btn-resend-cooldown-n) + 0.49);
opacity: 0;
visibility: hidden;
transition:
--btn-resend-cooldown-n 6s linear,
opacity 0.25s ease 6s,
visibility 0s 6.25s;
}
.btn-resend-cooldown-wait::before { content: "Resend in " counter(btn-resend-cooldown-n) "s"; }
.btn-resend-cooldown-wait::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 0.2em;
background: var(--c);
opacity: 0.6;
transform: scaleX(0);
transform-origin: left;
transition: transform 6s linear;
}
.btn-resend-cooldown-btn:active { transform: scale(0.96); }
.btn-resend-cooldown-btn:active + .btn-resend-cooldown-wait {
--btn-resend-cooldown-n: 6;
opacity: 1;
visibility: visible;
transition: none;
}
.btn-resend-cooldown-btn:active + .btn-resend-cooldown-wait::after {
transform: scaleX(1);
transition: none;
}
@media (prefers-reduced-motion: reduce) {
.btn-resend-cooldown, .btn-resend-cooldown *, .btn-resend-cooldown::before, .btn-resend-cooldown::after, .btn-resend-cooldown *::before, .btn-resend-cooldown *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--btn-color on the element or a parent.
Currently previewing #3b82f6.--btn-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.