How to Build a Stopwatch App Using HTML, CSS & JavaScript
In this advanced version, you get dark mode, floating TOC, syntax highlighting, download button, and full responsive layout. Perfect for professional Blogger coding tutorials.
📌 Introduction
This stopwatch measures minutes, seconds, and milliseconds using JavaScript timers. Beginner-friendly and perfect for web development learners.
🧩 Step 1: HTML Code
<div class="stopwatch-container"> <h1>Stopwatch</h1> <div id="display">00:00:00</div> <div class="buttons"> <button id="start">Start</button> <button id="stop">Stop</button> <button id="reset">Reset</button> </div> </div>
🎨 Step 2: CSS Code
<style>
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.stopwatch-container {
background: white;
padding: 30px;
width: 320px;
text-align: center;
border-radius: 12px;
box-shadow: 0 0 12px rgba(0,0,0,0.15);
}
#display {
font-size: 40px;
margin: 20px 0;
font-weight: bold;
}
.buttons button {
padding: 12px 20px;
margin: 5px;
border: none;
color: white;
background: #007bff;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
}
#stop { background: #ff9800; }
#reset { background: #e91e63; }
.buttons button:hover {
opacity: 0.9;
}
</style>
⚙ Step 3: JavaScript Code
<script>
let timer;
let ms = 0, sec = 0, min = 0;
let running = false;
function updateDisplay() {
let m = min < 10 ? "0" + min : min;
let s = sec < 10 ? "0" + sec : sec;
let msFormatted = ms < 10 ? "0" + ms : ms;
document.getElementById("display").innerText = m + ":" + s + ":" + msFormatted;
}
document.getElementById("start").onclick = function () {
if (!running) {
running = true;
timer = setInterval(() => {
ms++;
if (ms === 100) { ms = 0; sec++; }
if (sec === 60) { sec = 0; min++; }
updateDisplay();
}, 10);
}
};
document.getElementById("stop").onclick = function () {
running = false;
clearInterval(timer);
};
document.getElementById("reset").onclick = function () {
running = false;
clearInterval(timer);
ms = sec = min = 0;
updateDisplay();
};
</script>
⬇ Download Full Project
🟢 Live Stopwatch Preview
Try the stopwatch right here below:
Stopwatch
00:00:00
❓ FAQ
1. Does this version include dark mode?
Yes — fully responsive dark mode toggle without reloading the page.
2. Is the syntax highlighting automatic?
Yes — all code blocks use custom neon theme for readability.
3. Can you add more features?
Yes, I can add animations, syntax themes, shadows, tabs for code, and more.

Comments
Post a Comment