A stopwatch counts up from zero — useful for timing events, workouts, or experiments. A timer counts down from a set duration — useful for cooking, pomodoro sessions, or reminders. Both run in your browser using high-resolution timing APIs for accuracy.
Both features use performance.now(), which returns the
time in milliseconds since the page loaded with sub-millisecond
precision. Unlike Date.now(), which can be affected by
system clock adjustments, performance.now() is
monotonic — it always moves forward.
The display updates roughly 60 times per second using
requestAnimationFrame(), which aligns with your screen's
refresh rate. This is much more accurate than setInterval(),
which can drift over time.
Each lap records two values: the split time (how long just that lap took) and the total time (cumulative from the start). The split is the difference between the current time and the previous lap's timestamp. This lets you see both individual lap performance and overall progress.
The timer stores a target end time — the moment it should finish — rather than counting down tick by tick. Each display update computes the remaining time as:
This approach means the timer stays accurate even if the browser throttles background tabs or the display refresh rate drops. When the remaining time reaches zero, the timer plays a chime using the Web Audio API — no audio files needed.
performance.now()), but the display update pauses while
the tab is hidden. When you switch back, the display catches up
instantly to the correct elapsed time.
performance.now() in modern browsers.
Display updates happen at roughly 60 Hz, but the underlying time is
more precise than the display can show.