About this set
A stopwatch card with a large tenths-of-a-second readout, a dark Start button that becomes Stop while running, Lap and Reset buttons in a lighter style, and a scrolling list of split times with the newest lap on top. Use it for workout and cooking apps, timed exercises, usability tests or any interface where someone measures how long something takes. Elapsed time is always Date.now() minus the moment Start was pressed, plus any time banked before a pause, so it stays accurate when the tab is in the background and the browser throttles timers; requestAnimationFrame only redraws the digits while the stopwatch runs and stops when it is paused. The script works on every [data-stopwatch] element, so several can share a page. The buttons are real button elements, and the laps are an ordered list that becomes keyboard focusable once it holds entries, so it can be scrolled without a mouse. The Bootstrap version uses .card and .btn restyled through their CSS variables, and the Tailwind version uses utility classes only.
What’s included
- Start and stop, lap and reset on real buttons
- Elapsed time from Date.now() timestamps, accurate in background tabs
- Display redrawn with requestAnimationFrame only while running
- Scrolling lap list, newest first
- Start, stop, lap and reset announced through a polite live region
Accessibility
The controls are native buttons with visible text and a 2px blue focus outline. A visually hidden polite live region announces Started, Stopped at 1 minute 23.4 seconds, each lap and Reset, while the running digits are not announced. The lap list has an accessible name and becomes focusable once it has entries, and the button hover fade is removed under prefers-reduced-motion.
Customise it
Change the card and button colours on .sw, .sw button and .sw button.ghost in plain CSS. In Bootstrap edit the --bs-btn-* variables on .sw .btn and .sw .btn-light and the --bs-card-* variables on .sw; in Tailwind the bg-, text- and outline- utilities on each button.






