The border empties clockwise from the top like a timer while the number counts down, then refills. The number is a CSS counter fed by a registered @property integer, so no script runs it.
Also known as: border countdown timer css, border progress animation, timer border css.
<div class="bdr-countdown-timer-border">
<svg class="bdr-countdown-timer-border-svg" viewBox="0 0 150 85" preserveAspectRatio="none" aria-hidden="true">
<path class="bdr-countdown-timer-border-track" d="M75 0H140A10 10 0 0 1 150 10V75A10 10 0 0 1 140 85H10A10 10 0 0 1 0 75V10A10 10 0 0 1 10 0Z"/>
<path class="bdr-countdown-timer-border-time" d="M75 0H140A10 10 0 0 1 150 10V75A10 10 0 0 1 140 85H10A10 10 0 0 1 0 75V10A10 10 0 0 1 10 0Z" pathLength="100"/>
</svg>
<span>Resend code in <span class="bdr-countdown-timer-border-n"></span>s</span>
</div>@property --bdr-countdown-timer-border-n {
syntax: "<integer>";
inherits: false;
initial-value: 5;
}
.bdr-countdown-timer-border {
--c: var(--bdr-color, #3b82f6);
font-size: var(--bdr-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 15em;
height: 8.5em;
border-radius: 1em;
font-family: system-ui, sans-serif;
font-weight: 600;
--t: 6s;
background: color-mix(in srgb, var(--c) 5%, transparent);
font-variant-numeric: tabular-nums;
}
.bdr-countdown-timer-border-svg {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.bdr-countdown-timer-border-svg path {
fill: none;
stroke-width: 1.6;
}
.bdr-countdown-timer-border-track { stroke: color-mix(in srgb, var(--c) 16%, transparent); }
.bdr-countdown-timer-border-time {
stroke: var(--c);
stroke-linecap: round;
stroke-dasharray: 100 100;
animation: bdr-countdown-timer-border-drain var(--t) linear infinite;
}
.bdr-countdown-timer-border-n {
counter-reset: bdr-countdown-timer-border var(--bdr-countdown-timer-border-n);
color: var(--c);
animation: bdr-countdown-timer-border-count var(--t) infinite;
}
.bdr-countdown-timer-border-n::after { content: counter(bdr-countdown-timer-border); }
@keyframes bdr-countdown-timer-border-drain {
0% { stroke-dashoffset: 0; }
83.33% { stroke-dashoffset: -100; animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1); }
100% { stroke-dashoffset: -200; }
}
@keyframes bdr-countdown-timer-border-count {
0% { --bdr-countdown-timer-border-n: 5; animation-timing-function: steps(5, end); }
83.33% { --bdr-countdown-timer-border-n: 0; }
83.34%, 100% { --bdr-countdown-timer-border-n: 5; }
}
@media (prefers-reduced-motion: reduce) {
.bdr-countdown-timer-border, .bdr-countdown-timer-border *, .bdr-countdown-timer-border::before, .bdr-countdown-timer-border::after, .bdr-countdown-timer-border *::before, .bdr-countdown-timer-border *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--bdr-color on the element or a parent.
Currently previewing #3b82f6.--bdr-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.