Countdown Timer

Set a duration in minutes and seconds, then start a visual countdown with completion alert.

Back to all tools on ToolForge

More in Date & Time

Minutes

Seconds



01:00

About Countdown Timer

This countdown timer provides a visual way to track time remaining for any activity. Set your duration in minutes and seconds, start the countdown, and monitor the MM:SS display. A message appears when time expires.

Timer Algorithm

The countdown logic follows these steps:

  1. Parse input: Read minutes and seconds from form fields
  2. Convert: Total seconds = (minutes × 60) + seconds
  3. Start interval: setInterval() calls decrement function every 1000ms
  4. Decrement: remaining = remaining - 1
  5. Format display: MM:SS with zero-padding (padStart(2, "0"))
  6. Check completion: If remaining ≤ 0, clearInterval() and show message
JavaScript Countdown Implementation:

var tid = null;        // Timer interval ID
var remaining = 0;     // Seconds remaining
var original = 0;      // For reset functionality

function start() {
  if (tid) return;  // Already running

  var min = parseInt(document.getElementById("min").value) || 0;
  var sec = parseInt(document.getElementById("sec").value) || 0;
  remaining = (min * 60) + sec;
  original = remaining;

  tid = setInterval(function() {
    remaining--;
    if (remaining <= 0) {
      clearInterval(tid);
      tid = null;
      document.getElementById("msg").innerText = "Time's up!";
    }
    updateDisplay();
  }, 1000);
}

function updateDisplay() {
  var m = Math.floor(remaining / 60);
  var s = remaining % 60;
  var mm = String(m).padStart(2, "0");
  var ss = String(s).padStart(2, "0");
  document.getElementById("display").innerText = mm + ":" + ss;
}

Duration Conversion Reference

Minutes Seconds Common Use
1 60 Quick tasks, breathing exercises
5 300 Short breaks, warm-up
10 600 Quick workout, meditation
15 900 Power nap, short meeting
25 1500 Pomodoro work session
30 1800 Standard meeting, TV episode
45 2700 Class period, workout
60 3600 Full meeting, lecture

Browser Timer Throttling Behavior

Modern browsers reduce timer frequency in background tabs to save battery:

Browser Foreground Background
Chrome (88+) ~1ms minimum 1000ms minimum
Firefox (5+) ~4ms minimum 1000ms after 10s
Safari (6+) ~10ms minimum Throttled (undocumented)
Edge (Chromium) ~1ms minimum 1000ms minimum

Timer Accuracy Factors

Time Display Format (MM:SS)

The timer uses zero-padded MM:SS format for consistent visual width:

Format: MM:SS (minutes:seconds, zero-padded)

Examples:
  0 seconds  → 00:00
  5 seconds  → 00:05
  60 seconds → 01:00
  125 seconds → 02:05
  3661 seconds → 61:01

JavaScript zero-padding:
  String(5).padStart(2, "0")  → "05"
  String(30).padStart(2, "0") → "30"

Common Timer Use Cases

Timer Limitations

How to Use the Countdown Timer

  1. Set minutes: Enter the number of minutes (e.g., 5 for five minutes).
  2. Set seconds: Enter additional seconds (0-59) if needed.
  3. Start: Click "Start" to begin the countdown.
  4. Monitor: Watch the MM:SS display count down to zero.
  5. Complete: When time expires, "Time's up!" appears below the display.
  6. Reset: Enter new values and click Start, or use Reset to restore original duration.

Tips

Frequently Asked Questions

How does the countdown timer work?
The timer converts your input (minutes + seconds) to total seconds, then uses JavaScript's setInterval() to decrement every 1000ms. Remaining time is formatted as MM:SS with zero-padding. When remaining reaches 0, the timer stops and displays a completion message.
Will the timer work if I switch to another tab?
Yes, but accuracy may decrease. Modern browsers throttle setInterval/setTimeout in background tabs to conserve battery—typically limiting to 1000ms minimum, sometimes slower. For short timers (under 30 minutes), the drift is negligible. For precise timing, keep the tab visible.
Why do browsers throttle background timers?
Browser timer throttling reduces power consumption and CPU usage when tabs are not visible. Chrome, Firefox, Safari, and Edge all implement throttling: Chrome limits background timers to 1000ms, Firefox to 1000ms after 10 seconds of backgrounding, Safari similarly. This extends battery life on mobile devices.
What is the maximum timer duration?
Technically, JavaScript numbers can represent ~248 days of seconds. Practically, you can set timers for hours. However, browser throttling, sleep mode, or tab crashes may interrupt very long timers. For multi-hour countdowns, dedicated timer apps or system alarms are more reliable.
How accurate is this timer?
In foreground tabs: ±1 second under normal conditions. In background tabs: may drift by several seconds per hour due to browser throttling. setInterval is not perfectly precise—JavaScript is single-threaded, so heavy page activity can cause minor delays. For most use cases (cooking, workouts, Pomodoro), this accuracy is sufficient.
Can I add custom sounds or notifications?
This implementation shows a visual message. To add audio, you would need to integrate the Web Audio API or HTML5