HTML ontimeupdate Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The ontimeupdate attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the timeupdate event fires — the media’s currentTime has been updated.

The event is not cancelable and does not bubble. It fires often (roughly 4–66 Hz, depending on system load) while time advances during play or seek. Use it for clocks and progress UIs. Contrast with onseeked (one-shot seek done) and ondurationchange (total length changed).

Baseline · Widely available.

Not deprecated and not experimental. The timeupdate event is stable across modern browsers since about July 2015.

Prefer addEventListener in apps.

Inline ontimeupdate is fine for learning. Production code usually uses media.addEventListener("timeupdate", handler). Keep the handler cheap — it can run many times per second.

HTML Syntax

syntax.html
<video|audio ontimeupdate=" script">

script is JavaScript that runs when timeupdate fires. Equivalent JS: media.ontimeupdate = handler or media.addEventListener("timeupdate", handler).

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript when currentTime updatesTry it
ontimeupdate="fn()"Call a named function from the attributeTry it
addEventListener("timeupdate")Preferred modern listener on audio/videoTry it
Progress %currentTime / duration for a simple meterTry it
+ controlsPlay with native UI; still sync your custom clockTry it

Live Preview

Press play. The clock updates as timeupdate fires.

Media

Sample /video/count.mp4 or /audio/count.mp3.

Player

0.0 s

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline ontimeupdate on Video

Show currentTime while the video plays.

HTML
<video id="clip" width="400" height="225" controls ontimeupdate="showTime()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="clock">0.0 s</p>

<script>
  function showTime() {
    var t = document.getElementById("clip").currentTime.toFixed(1);
    document.getElementById("clock").textContent = t + " s";
  }
</script>
Try It Yourself

How It Works

  1. Put ontimeupdate on the media element — here <video>.
  2. User presses Play — currentTime advances.
  3. timeupdate fires repeatedly as time changes.
  4. Handler updates the clock from currentTime.

Example 2 — addEventListener on Audio

Preferred script pattern with a simple formatted time.

HTML
<audio id="clip" controls>
  <source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<p id="log">0.0 / —</p>

<script>
  document.getElementById("clip").addEventListener("timeupdate", function () {
    var now = this.currentTime.toFixed(1);
    var total = isFinite(this.duration) ? this.duration.toFixed(1) : "—";
    document.getElementById("log").textContent = now + " / " + total + " s";
  });
</script>
Try It Yourself

How It Works

  1. Select the audio with getElementById.
  2. Register timeupdate with addEventListener.
  3. Read currentTime and duration each tick.
  4. Guard duration with isFinite until metadata is ready.

Example 3 — Simple progress percent

Drive a text progress readout from currentTime / duration.

HTML
<video id="clip" width="400" height="225" controls>
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="pct">0%</p>

<script>
  document.getElementById("clip").addEventListener("timeupdate", function () {
    if (!isFinite(this.duration) || this.duration === 0) return;
    var p = Math.floor((this.currentTime / this.duration) * 100);
    document.getElementById("pct").textContent = p + "%";
  });
</script>
Try It Yourself

How It Works

  1. Wait for a real duration — skip until finite and non-zero.
  2. Each timeupdate compute percent from currentTime.
  3. Update a light UI — text or a progress bar width.
  4. For seek-only UI also listen to seeked.

Edge Cases & Pitfalls

Most issues come from heavy work inside a high-frequency handler, or reading duration too early.

frequency

Fires many times per second

About 4–66 Hz. Avoid heavy DOM work, network, or canvas redraws every tick — throttle if needed.

vs seeked

Not a one-shot seek event

seeked means “jump finished.” timeupdate means “time value changed again” during play or seek.

duration

duration may be NaN at first

Wait for metadata (durationchange / loaded metadata) before dividing for percent.

bubble

Does not bubble

Listen on the audio/video element itself. Parent listeners will not see a bubbling timeupdate.

property

.ontimeupdate = replaces listeners

Assigning the IDL property overwrites a previous assignment. Prefer addEventListener for multiple handlers.

Browser Support

ontimeupdate is an HTML event-handler attribute for media elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

ontimeupdate

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the timeupdate event on audio and video.

97% Global support (approx.)
Google Chrome 3+
Full support
Mozilla Firefox 3.5+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 10.5+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 9+
Supported
ontimeupdate Widely supported

Bottom line: Safe to use for media clocks and progress. Prefer addEventListener in production, and keep handlers lightweight because of the high event rate.

Key Takeaways

  • Role: run script when currentTime is updated.
  • Use for: clocks, captions sync cues, progress meters.
  • Rate: frequent (≈4–66 Hz) — keep handlers light.
  • Seek done: use onseeked, not only ontimeupdate.

One line: ontimeupdate means “playback time changed again” — ideal for live clocks and progress, with a light handler.

Frequently Asked Questions

It is an event-handler attribute on audio or video. When the currentTime value is updated during playback (or seeking), the timeupdate event fires and the script runs — often used for custom clocks and progress bars.
The HTML audio and video elements. Put the handler on the media element itself.
About 4 to 66 times per second, depending on system load. User agents vary the rate so UI work stays comfortable. Keep handlers light.
ontimeupdate fires repeatedly as currentTime changes. onseeked fires once when a seek operation finishes. Use seeked for “jump done,” timeupdate for ongoing progress.
Both work. For learning, ontimeupdate in HTML is fine. In production code, prefer media.addEventListener("timeupdate", handler).
No. The timeupdate event and ontimeupdate handler are standard HTML media features and Baseline widely available since about July 2015.

Next: ontoggle

Handle open/close state changes on details and other toggleable elements.

ontoggle tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful