Timer

A timer is a UI/UX component that displays a countdown or elapsed time value in a live-updating format. It renders as a semantic HTML <time> element with role="timer", which is not a live region: a value that changes every second would flood a screen reader, so the reader hears it when they ask for it. The component is commonly used for session timeouts, countdowns, stopwatches, cooking timers, exam time limits, and any scenario where users need to track the passage of time. This headless component provides the semantic structure and accessibility features while the consumer manages the actual timer logic and provides formatted display content through the children slot.

Status: stable — exercised in composed page flows under e2e and axe, beyond the per-component checks.

Example

Show demo markup
<time class="timer" role="timer" aria-label="Time remaining" datetime="PT5M">05:00</time>
Usage example
<script lang="ts">
  import Timer from "./Timer.svelte";
</script>

<Timer label="Countdown">05:30</Timer>
Show Svelte source
// In your Svelte component:
import Timer from "lily-design-system-svelte-headless/components/Timer/Timer.svelte";

<Timer>
  <!-- content -->
</Timer>

Usage

<Timer
  label="Session timeout"
  datetime="PT5M30S"
  >05:30</Timer
>
<Timer
  label="Exam time remaining"
  datetime="PT45M00S"
  >45:00</Timer
>
<Timer label="Elapsed consultation time">{formatMinutesSeconds(elapsed)}</Timer>
<Timer
  label="Cooking timer"
  datetime="PT12M15S"
  >12:15</Timer
>

A reader who must hear the time hears a milestone, not every tick: the timer stays quiet, and a separate status region announces the consumer's own words when a milestone passes.

<Timer
  label="Session timeout"
  datetime="PT1M00S"
  >01:00</Timer
>
<p role="status">One minute left. Save your work.</p>

Props

  • label: string (required) -- accessible label for screen readers
  • children: slot (required) -- formatted timer display content
  • ...restProps: Any additional HTML attributes spread onto the <time> element

Keyboard Interactions

  • None -- this is an informational display, not interactive

ARIA

  • role="timer" indicates countdown or elapsed time
  • aria-label from the label prop provides accessible name
  • No aria-live: the timer is read on demand, and milestones go to a separate status region

When to Use

  • Use for countdown or elapsed time display, such as session timeout, exam timer, or cooking timer.
  • Use with a separate role="status" region when a reader must hear a milestone, such as "one minute left".
  • Use with the datetime attribute for machine-readable ISO 8601 durations.
  • Use when the displayed time updates dynamically via consumer-managed intervals.

When Not to Use

  • Do not use for static time display -- show the time as plain text or a <time> element.
  • Do not use for auto-triggering actions on countdown -- use TimerButton instead.
  • Do not use when time remaining is better shown as a proportion -- use Progress or Meter instead.
  • Misuse: a visible countdown used to pressure a decision ("3 people are looking at this"), or a limit the user cannot adjust. Show a timer only for a real limit, and give a way to extend it (WCAG 2.2.1).

Headless

This headless component provides a <time> element with role="timer" and aria-label, not live, for an accessible time display. The consumer manages all timer logic (intervals, countdowns) and provides formatted display content through the children slot, plus all visual styling.

Styles

The consumer provides all CSS styling. The component renders with a .timer class for targeting. No default styles are included — this is a fully headless component.

Testing

  • Verify the component renders a <time> element with class timer
  • Verify role="timer"` indicates countdown or elapsed time
  • Verify aria-label` from the label prop provides accessible name
  • Verify keyboard interactions work correctly
  • Verify pass-through attributes are applied

Advice

  • Designers: Use a clear, monospaced or tabular font for the timer digits to prevent layout shifts as numbers change. Consider color changes as time runs low.
  • Accessibility: Never make the timer itself live. Put milestone announcements ("five minutes left", "time is up") in a separate role="status" region (role="alert" only for the last one, if it ends the user's work), updated only when a milestone passes; WCAG 2.2.1 also asks that the user can extend a time limit.
  • Developers: Provide a datetime attribute (e.g., datetime="PT5M30S") via restProps for machine-readable duration. Manage cleanup of intervals on component unmount.

Implementation Notes

  • Renders as <time role="timer" aria-label={label}>
  • Children slot provides the formatted timer display text
  • Not a live region (role="timer" is aria-live="off"): announce milestones ("one minute left") in a separate role="status" region, never every tick
  • Consumer manages timer logic (intervals, countdowns); this component only provides structure and accessibility
  • Optional datetime attribute can be passed via restProps for machine-readable duration (e.g. datetime="PT5M30S")

Related components

  • timer-button — a button with a timer that will automatically click after a given amount of time
  • loading — a loading indicator, such as text, or image, or animation
  • date-time-view — see components.tsv

Known limitations

None known.

References


Lily™ and Lily Design System™ are trademarks.

Canonical contract

Generated from this component's canonical metadata — the machine-checked source the implementations are held to.

Metadata

  • Component: timer
  • PascalCase: Timer
  • Description: a countdown or elapsed time display
  • Purpose: Shows a real countdown or elapsed time, such as a session limit, in a form the user can read, and is never used to pressure a decision.
  • Status: stable — exercised in composed page flows under e2e and axe, beyond the per-component checks
  • HTML tag: <time>
  • CSS class: .timer
  • Interactive: no

ARIA

  • role="timer" indicates countdown or elapsed time
  • aria-label from the label prop provides accessible name
  • No aria-live: the timer is read on demand, and milestones go to a separate status region

Keyboard

  • None -- this is an informational display, not interactive

Props

  • label: string (required) -- accessible label for screen readers
  • children: slot (required) -- formatted timer display content
  • ...restProps: Any additional HTML attributes spread onto the <time> element

Markdown

This page as Markdown, for people and AI tools: timer.md