A live pill says 1,284 viewing now: a green dot pings while the last two digits roll up or down to each new count, like a real-time analytics badge. Pure CSS digit strips and keyframes.
Also known as: live visitor counter css, people viewing now animation, real time counter css, odometer css.
<div class="txt-live-visitor-counter" aria-label="About 1,284 people viewing now"> <span class="txt-live-visitor-counter-dot" aria-hidden="true"></span> <span class="txt-live-visitor-counter-num" aria-hidden="true">1,2<span class="txt-live-visitor-counter-col"><span class="txt-live-visitor-counter-tens">89</span></span><span class="txt-live-visitor-counter-col"><span class="txt-live-visitor-counter-ones">4567890123456</span></span></span> <span class="txt-live-visitor-counter-text" aria-hidden="true">viewing now</span> </div>
.txt-live-visitor-counter {
--c: var(--txt-color, #3b82f6);
font-size: calc(var(--txt-size, 32px) * 0.75);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: inline-flex;
align-items: center;
gap: 0.5em;
padding: 0.45em 0.95em 0.45em 0.8em;
border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
border-radius: 99em;
background: color-mix(in srgb, currentColor 3%, transparent);
box-shadow: 0 0.05em 0.1em rgb(0 0 0 / 0.04), 0 0.4em 1em -0.5em rgb(0 0 0 / 0.18);
font-weight: 600;
--t: 9.6s;}
.txt-live-visitor-counter-dot {
position: relative;
width: 0.45em;
height: 0.45em;
border-radius: 50%;
background: #22c55e;
}
.txt-live-visitor-counter-dot::after {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
background: #22c55e;
animation: txt-live-visitor-counter-ping 1.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
.txt-live-visitor-counter-num {
display: inline-flex;
font-variant-numeric: tabular-nums;
letter-spacing: -0.01em;
}
.txt-live-visitor-counter-col {
display: inline-block;
height: 1.25em;
overflow: hidden;
line-height: 1.25em;
-webkit-mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}
.txt-live-visitor-counter-col > span {
display: block;
width: 1ch;
text-align: center;
word-break: break-all;
}
.txt-live-visitor-counter-tens { animation: txt-live-visitor-counter-tens var(--t) infinite; }
.txt-live-visitor-counter-ones { animation: txt-live-visitor-counter-ones var(--t) infinite; }
.txt-live-visitor-counter-text {
font-weight: 500;
opacity: 0.6;
}
@keyframes txt-live-visitor-counter-ping {
0% { transform: scale(1); opacity: 0.55; }
70%, 100% { transform: scale(2.8); opacity: 0; }
}
@keyframes txt-live-visitor-counter-tens {
0% { transform: translateY(0); }
11.46% { transform: translateY(0); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
18.75% { transform: translateY(0); }
27.08% { transform: translateY(0); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
34.38% { transform: translateY(0); }
43.75% { transform: translateY(0); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
51.04% { transform: translateY(-1.25em); }
57.29% { transform: translateY(-1.25em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
64.58% { transform: translateY(-1.25em); }
73.96% { transform: translateY(-1.25em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
81.25% { transform: translateY(0); }
88.54% { transform: translateY(0); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
95.83% { transform: translateY(0); }
100% { transform: translateY(0); }
}
@keyframes txt-live-visitor-counter-ones {
0% { transform: translateY(0); }
11.46% { transform: translateY(0); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
18.75% { transform: translateY(-3.75em); }
27.08% { transform: translateY(-3.75em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
34.38% { transform: translateY(-1.25em); }
43.75% { transform: translateY(-1.25em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
51.04% { transform: translateY(-8.75em); }
57.29% { transform: translateY(-8.75em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
64.58% { transform: translateY(-15em); }
73.96% { transform: translateY(-15em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
81.25% { transform: translateY(-5em); }
88.54% { transform: translateY(-5em); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
95.83% { transform: translateY(0); }
100% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
.txt-live-visitor-counter, .txt-live-visitor-counter *, .txt-live-visitor-counter *::before, .txt-live-visitor-counter *::after { animation: none !important; }
}
@media (prefers-reduced-motion: reduce) {
.txt-live-visitor-counter, .txt-live-visitor-counter *, .txt-live-visitor-counter::before, .txt-live-visitor-counter::after, .txt-live-visitor-counter *::before, .txt-live-visitor-counter *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.