Timer

<o-timer> is a countdown ring with start, pause and reset.

The time left is an <o-progress> on orbit-12 that shrinks back toward 12 o'clock. The buttons in the middle are real buttons inside the center capsule. The ring is redrawn in small steps rather than every frame, and the digits change once a second.

Attributes

AttributeDefaultWhat it does
duration60Length of the countdown: seconds (90 or 90s), m:ss or h:mm:ss.
remainingdurationTime left to start from, in the same formats.
runningoffPresent while the timer runs. Add it to start, remove it to pause.
labelA caption under the time. It is also part of the accessible name.
warnWhen the time left drops to this, the ring takes the warning color.
ticks0Marks around the inside of the ring, such as 60 or 12.
controlsoncontrols="false" hides the buttons, for a timer you drive from code.
fill / track#3da9fc / faint grayRing colors.
thickness1.4Ring thickness in lanes.
shaperoundedEnding of the ring.
size200pxWidth of the widget.
glowoffA glow in the ring color.
themedark, light or glass. Also inherited from an ok-theme-* class on a container. See Shared options.

Properties, methods and events

NameWhat it does
start(), pause(), toggle(), reset()Control the countdown. start() after the end starts over.
remainingSeconds left. You can set it, also while running.
runningtrue while counting down. Setting it starts or pauses.
durationLength in seconds. Setting it writes the attribute.
start, pause, resetFire when the state changes.
tickFires each time the shown second changes while running.
doneFires once when the time is up.

The methods exist once the element is defined. A classic script that runs before the kit module can write running instead, or wait for customElements.whenDefined('o-timer').

Every event bubbles and carries remaining and duration in event.detail. While it runs, the element has the class is-running; near the end is-warning, and at zero is-done.

Styling

PropertyDefaultWhat it does
--ok-fill#3da9fcRing and main button.
--ok-trackfaint grayTrack.
--ok-timer-warn#f59e0bRing color in the warning time.
--ok-timer-done#ef4565Ring color at zero.
--ok-timer-button--ok-fillBackground of the start and pause button.
--ok-timer-button-text#0c0f13Its icon color.
--ok-timer-button-alttranslucent grayBackground of the reset button.
--ok-tickcurrentColorTick marks.
--ok-font-size8cqminBase text size.

More examples

A dial with a warning

The ring turns amber in the last five seconds.

Driven from code

A light pomodoro

Accessibility

The timer has role="timer" and a name like “Tea: 1:30 left of 1:30”. The ticking digits are not announced, which is how a timer should behave. When the time is up, a polite live region says so (“Tea: time is up”). The buttons are named Start, Pause, Resume and Reset as the state changes, and work with Enter and Space like any button.