A polished single-page Stopwatch + Countdown Timer built with plain HTML/CSS/JavaScript.
No dependencies, no build step—open it in a browser or serve it from any static web server.
https://stopwatch.fcjamison.com/
- Digital output formatted as
mm:ss:hh(minutes : seconds : hundredths) - Start/Pause/Resume toggle + Clear
- Analog face rendering (PNG face + layered hands rotated via JavaScript)
- Strict input validation for exact
mm:ss:hh - Start/Pause/Resume toggle + Clear
- Stops at
00:00:00and displays “Time is up!” - Maximum start time:
10:00:00
- HTML: index.html
- CSS: css/myStyles.css
- JavaScript: js/myScript.js
- Assets: images/
- Internal unit is hundredths of a second (the code increments every ~10ms)
- Display format is
mm:ss:hh(always 2 digits per segment)
In js/myScript.js, state is kept in a few globals:
- Stopwatch:
watchTime,watchIsRunning - Countdown:
timerTime,timerStartTime,timerIsRunning
DOM references are cached once on window.onload in a ui object.
The analog hands are positioned in CSS and rotated in updateAnalogHands(time) using style.transform.
index.html
README.md
css/
myStyles.css
images/
stopwatch.png
hand-minute.svg
hand-second-red.svg
js/
myScript.js
Open index.html in a modern browser.
Serving from http://localhost/... avoids some browser quirks and makes refresh/testing more consistent.
Pick one:
-
Python 3 (from the repo root):
python -m http.server 8080- open
http://localhost:8080/
-
Node (no install; uses
npx):npx --yes http-server -p 8080 .- open
http://localhost:8080/
-
VS Code extension: use “Live Server” and open the served URL.
This workspace includes a VS Code task that opens Chrome to:
http://stopwatchandcountdowntimer.localhost/
Run it via Terminal → Run Task… → Open in Browser (or Tasks: Run Task).
Notes:
- The task is defined in .vscode/tasks.json.
- This repo ignores
.vscode/via .gitignore, so you may need to recreate the task in your own workspace. - Many setups treat
*.localhostas loopback; if your machine doesn’t resolve it, add a hosts entry (see next section). - If you prefer a different URL (like
http://localhost:8080/), edit the task’s URL string.
If http://stopwatchandcountdowntimer.localhost/ doesn’t resolve on your machine:
- Edit your hosts file (Windows):
C:\Windows\System32\drivers\etc\hosts
- Add:
127.0.0.1 stopwatchandcountdowntimer.localhost
- Serve this folder from a local web server and point that host name at the repo root.
Because this is a static site, any web server works (IIS, Apache, nginx, etc.).
- Press Start to begin.
- Press Pause to stop.
- Press Clear to reset.
- Enter a start time as
mm:ss:hh(example:01:30:00). - Press Start.
- Press Pause to pause.
- Press Clear to reset.
The CSS/JS includes a query string version in index.html (e.g. myScript.js?v=...).
If you change assets and want to force a fresh load:
- bump the
v=...value in index.html, or - hard refresh in the browser (
Ctrl+Shift+R).
Countdown validation is strict by design:
- Format must be exactly
mm:ss:hh - Maximum allowed input is
10:00:00
If you want a different max, update the regex in validateStartTime() in js/myScript.js.
- Countdown won’t start: the input must match
mm:ss:hhexactly and be<= 10:00:00. - Timing looks off in background tabs: browsers can throttle timers in inactive tabs.
- Changes not showing up: hard refresh (
Ctrl+Shift+R) or bump the query-string version in index.html.