References

Beginner-friendly references for web development, with live, editable examples.

The HTML onseeked event

Event All modern browsers
In short

The HTML onseeked attribute runs JavaScript once a seek in <audio> or <video> has landed. In <video onseeked="updateLabel(this)">, the label changes once the jump is complete. By then seeking is false and currentTime holds the new position.

Overview

The HTML onseeked attribute runs code at the end of a seek, once audio or video reaches its target. The seeked event fires after the playback position has changed and the seeking property is false again.

Every completed seek ends with a seeked event, and onseeking marks the start of the same jump.

A burst of seeks can end in one event. When code sets the position twice in a row, Chrome fires seeking for each change but seeked only once, for the final position. Counting seeked events can therefore undercount jumps.

Inside the handler, the new position is settled. That makes seeked the moment to update a time label, sync anything tied to the timeline, or record that a viewer skipped ahead.

Syntax

<video src="clip.mp4" controls onseeked="updateLabel(this)"></video>

Example

Live example
<video id="clip" src="https://codeshack.io/web/example.mp4" controls muted width="240" onseeked="landed(this)"></video>
<p>
  <button type="button" data-t="5">0:05</button>
  <button type="button" data-t="15">0:15</button>
  <button type="button" data-t="25">0:25</button>
</p>
<p id="msg" role="status">Pick a chapter or drag the progress bar.</p>
<script>
for (const b of document.querySelectorAll('button[data-t]')) {
  b.addEventListener('click', function () {
    document.getElementById('clip').currentTime = Number(b.dataset.t);
  });
}
function landed(video) {
  const s = Math.round(video.currentTime);
  document.getElementById('msg').textContent = 'Now at 0:' + String(s).padStart(2, '0');
}
</script>

Best practices

  • Update time labels and chapter highlights in onseeked rather than onseeking, because the position is final by then.
  • Don't treat seeked as a sign that playback resumed. Seeking doesn't start playback, so a paused video is still paused afterward.
  • Give jump buttons visible text such as 0:15, so the target time is clear without a tooltip.
  • Check video.loop or the position before counting a seek as a skip ahead, since a looping video also fires seeked when it wraps back to the start.

Accessibility

Announce where playback landed from onseeked, with a status message such as "Now at 0:15". Make chapter and jump controls real buttons with readable labels, so keyboard and screen reader users can move through the video the same way as mouse users.

Frequently asked questions

What does onseeked do?
The onseeked attribute runs JavaScript after a seek has landed, once the element's seeking property is false again. Use it for work that needs the final position, such as updating a time label.
Does the browser wait for the new frame before firing seeked?
Yes, if the media data is available, the browser decodes enough to play the new position before seeked fires.
Why did onseeked fire only once for two seeks?
The seeked event marks the end of seeking, so rapid jumps can share one event. In Chrome, two currentTime changes in a row fire seeking twice and seeked once.
Which property holds the new position in onseeked?
Read the element's currentTime, which gives the settled position in seconds once onseeked runs. Round or format it as needed for a time label.
Can I cancel a seek with onseeked?
No, by the time the seeked event fires, the jump has already happened. Set currentTime again inside the handler if the position must be moved somewhere else.