<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cumulative Counter Since 2020</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: Tahoma, sans-serif;
background: linear-gradient(135deg, #eef2ff, #f8fafc);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.wrapper {
text-align: center;
padding: 2rem;
}
.title {
font-size: 16px;
color: #666;
margin-bottom: 1.5rem;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
max-width: 480px;
margin: 0 auto 14px;
}
.box {
background: #fff;
border: 1px solid #ddd;
border-radius: 14px;
padding: 1.2rem 0.5rem;
text-align: center;
transition: all 0.2s;
cursor: default;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.box:hover {
transform: translateY(-4px) scale(1.03);
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
.box .num {
font-size: 42px;
font-weight: bold;
color: #222;
line-height: 1.1;
}
.box .lbl {
font-size: 14px;
color: #999;
margin-top: 8px;
}
/* Highlight seconds */
.box.sec {
border-color: #3b82f6;
background: #eff6ff;
}
.box.sec .num { color: #1d4ed8; }
.box.sec .lbl { color: #3b82f6; }
/* Highlight years */
#b-y {
background: #fef3c7;
border-color: #f59e0b;
}
#b-y .num { color: #b45309; }
/* Animation */
@keyframes pop {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.animate {
animation: pop 0.25s ease;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="title" id="title"></div>
<div class="grid">
<div class="box" id="b-y"><div class="num" id="v-y">00</div><div class="lbl">Years</div></div>
<div class="box" id="b-mo"><div class="num" id="v-mo">00</div><div class="lbl">Months</div></div>
<div class="box" id="b-d"><div class="num" id="v-d">00</div><div class="lbl">Days</div></div>
</div>
<div class="grid">
<div class="box" id="b-h"><div class="num" id="v-h">00</div><div class="lbl">Hours</div></div>
<div class="box" id="b-mi"><div class="num" id="v-mi">00</div><div class="lbl">Minutes</div></div>
<div class="box sec" id="b-s"><div class="num" id="v-s">00</div><div class="lbl">Seconds</div></div>
</div>
</div>
<script>
const start = new Date("2020-01-01T00:00:00");
const ids = ['y','mo','d','h','mi','s'];
const prev = {};
ids.forEach(k => prev[k] = -1);
function diff(s, e) {
let y = e.getFullYear() - s.getFullYear();
let mo = e.getMonth() - s.getMonth();
let d = e.getDate() - s.getDate();
let h = e.getHours() - s.getHours();
let mi = e.getMinutes() - s.getMinutes();
let sc = e.getSeconds() - s.getSeconds();
if (sc < 0) { sc += 60; mi--; }
if (mi < 0) { mi += 60; h--; }
if (h < 0) { h += 24; d--; }
if (d < 0) {
d += new Date(e.getFullYear(), e.getMonth(), 0).getDate();
mo--;
}
if (mo < 0) { mo += 12; y--; }
return { y, mo, d, h, mi, s: sc };
}
function tick() {
const t = diff(start, new Date());
const vals = { y: t.y, mo: t.mo, d: t.d, h: t.h, mi: t.mi, s: t.s };
ids.forEach(k => {
if (vals[k] !== prev[k]) {
const el = document.getElementById('v-' + k);
el.textContent = String(vals[k]).padStart(2, '0');
el.classList.remove('animate');
void el.offsetWidth;
el.classList.add('animate');
prev[k] = vals[k];
}
});
}
/* Dynamic title */
function updateTitle() {
const now = new Date();
document.getElementById("title").textContent =
"Since January 1, 2020 — " + now.toLocaleString();
}
tick();
updateTitle();
setInterval(() => {
tick();
updateTitle();
}, 1000);
</script>
</body>
</html>