Simple Countdown Timer
Home
Snippets
Simple Countdown Timer
HTML
CSS
JS
<div id="timer">00 : 30</div>
body { height: 100vh; margin: 0; background: #222; color: #fff; font-family: sans-serif; display: flex; align-items: center; justify-content: center; } #timer { font-size: 3em; background: #000; padding: 20px 80px; border-radius: 10px; box-shadow: 3px 3px 2px #0f0; }
let seconds = 30; function updateTimer() { const timer = document.getElementById('timer'); const mins = String(Math.floor(seconds / 60)).padStart(2, '0'); const secs = String(seconds % 60).padStart(2, '0'); timer.textContent = `${mins} : ${secs}`; if (seconds > 0) seconds--; } updateTimer(); setInterval(updateTimer, 1000);
Ad #1
Ad #2
Scroll to Top