HTML onseeking Attribute

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Events & Handlers

Introduction

The onseeking attribute is an inline event handler that runs JavaScript when the seeking event fires on an audio or video element. It runs when a seek operation starts — as the user begins dragging the progress bar or when your code sets currentTime. Use it to show a loading indicator, disable custom controls, or pause related animations while the browser jumps to a new position. Check media.seeking (true during seek). Pair with onseeked when seeking finishes. Prefer addEventListener("seeking", …) in production.

What You’ll Learn

01

Event handler

Inline JS.

02

seeking

Seek starts.

03

audio / video

Media only.

04

.seeking

Boolean flag.

05

+ onseeked

Seek done.

06

addEventListener

Preferred way.

Purpose of onseeking Attribute

The primary purpose of onseeking is to react when a seek operation begins — so your page can show “buffering” feedback, temporarily disable buttons, hide stale captions, or prepare UI before the new playback position is ready.

The seeking event fires on the media element when playback position is about to change. It is the counterpart to seeked, which fires when seeking is complete. Together they cover the full seek lifecycle.

💡
Start of seek, not the end

onseeking runs when scrubbing begins. Use onseeked to update the final timestamp or resume UI after the new position loads.

📝 Syntax

Set onseeking on <audio> or <video>, or assign element.onseeking in JavaScript:

onseeking.html
<video controls onseeking="handleSeeking()">
  <source src="/video/count.mp4" type="video/mp4">
</video>

<script>
  media.onseeking = handleSeeking;
  media.addEventListener("seeking", handleSeeking);
</script>

Syntax Rules

  • Value is JavaScript executed when the seeking event fires.
  • Valid on <audio> and <video> elements.
  • Fires when seek starts — user scrubbing or currentTime = ….
  • Check element.seekingtrue while seek is in progress.
  • Also assignable as element.onseeking in script.
  • Modern alternative: addEventListener("seeking", handler).
  • Pair with onseeked for seek-complete logic.

💎 Values

The onseeking attribute accepts a string of JavaScript code:

  • onseeking="handleSeeking()" — Call a named function.
  • onseeking="showSpinner()" — Show loading UI during scrub.
  • JavaScript: video.onseeking = () => { … } — property assignment.
onseeking-handler.html
function handleSeeking() {
  status.textContent = "Seeking…";
  status.classList.add("is-seeking");
}

function handleSeeked() {
  status.textContent = "Ready at " + formatTime(media.currentTime);
  status.classList.remove("is-seeking");
}

media.addEventListener("seeking", handleSeeking);
media.addEventListener("seeked", handleSeeked);

⚡ Quick Reference

Property / APIWhen it runsNotes
seekingSeek operation startsonseeking
seekedSeek operation completesonseeked
media.seekingRead anytimetrue while seeking
currentTimeRead anytimeTarget position (may update)
timeupdateDuring playbackNot seek-specific

Applicable Elements

ElementSupported?Notes
<video>YesPrimary use — progress bar scrubbing
<audio>YesSame seeking event on audio controls
<source>NoPut handler on parent media element
<iframe>NoEmbedded players are separate documents
<div>, <input>NoNot media elements

onseeking vs onseeked vs ontimeupdate

HandlerWhen it firesTypical use
onseekingSeek starts (scrub begins)Loading spinner, disable controls
onseekedSeek finishes (position ready)Update time label, sync UI
ontimeupdateDuring normal playbackProgress bar, elapsed time
onwaitingPlayback stalled (buffering)Network buffer indicator

Examples Gallery

Inline video handler, dynamic assignment, and paired seeking + seeked status labels.

👀 Live Preview

Drag the audio progress bar — status shows “Seeking…” then the new time:

Ready — scrub to seek

Example — onseeking on video

Run a function when the user starts scrubbing the seek bar:

video-onseeking.html
<video controls onseeking="handleSeeking()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status"></p>

<script>
  function handleSeeking() {
    document.getElementById("status").textContent = "Seeking…";
  }
</script>
Try It Yourself

How It Works

When the user starts moving the progress bar (or your code changes currentTime), the browser fires seeking and runs handleSeeking(). The new position may not be ready yet — that is what onseeked is for.

Dynamic Values with JavaScript

Assign the handler on a video element at runtime:

dynamic-onseeking.html
<script>
  document.getElementById("dynamicVideo").onseeking =
    function () {
      log.textContent = "Seeking event detected!";
    };
</script>
Try It Yourself

How It Works

Assigning element.onseeking is equivalent to the inline attribute. Use this when you attach the handler after the DOM loads or based on user interaction.

Example — Pair seeking and seeked

Show loading on seek start and final time on seek complete:

seeking-seeked-pair.html
media.addEventListener("seeking", function () {
  status.textContent = "Seeking…";
  status.setAttribute("aria-busy", "true");
});

media.addEventListener("seeked", function () {
  status.textContent = "Now at " + formatTime(this.currentTime);
  status.removeAttribute("aria-busy");
});
Try It Yourself

How It Works

seeking and seeked bookend every seek operation. Use both for polished custom players with clear user feedback.

♿ Accessibility

  • Announce seek state — Use aria-busy="true" and aria-live="polite" during seeking.
  • Keyboard seeking — Native controls support keyboard; custom seek UIs need arrow keys and focus styles.
  • Do not block controls — Disabling UI during seek should be brief and reversible.
  • Visible feedback — Show seek-in-progress to all users, not only via console or alerts.
  • Captions — Hide or dim stale subtitles during seek until seeked syncs the new position.

🧠 How onseeking Works

1

User starts scrubbing

Or code sets currentTime.

Input
2

seeking fires

onseeking runs.

Event
3

Browser loads position

seeking is true.

Buffer
=

Then seeked

Position ready — onseeked.

Browser Support

The seeking event and onseeking handler are supported in all modern browsers on HTML5 audio and video elements.

HTML5 Media · Fully supported

Universal onseeking support

All major browsers fire seeking when media seeking begins.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 9+ supported
Full support
Opera Fully supported
Full support
onseeking attribute 99% supported

Bottom line: Reliable for seek-start handling on HTML5 media in all modern browsers.

💡 Best Practices

✅ Do

  • Use onseeking for loading UI when scrubbing starts
  • Pair with onseeked to complete the seek lifecycle
  • Check media.seeking for current seek state
  • Use addEventListener("seeking", …) in production
  • Set aria-busy during seek for screen reader users

❌ Don’t

  • Confuse seeking with seeked (start vs end)
  • Put onseeking on non-media elements
  • Update final timestamps in onseeking — wait for onseeked
  • Rely on alert() for seek feedback
  • Leave controls disabled after seeked fails to fire

Conclusion

The onseeking attribute runs JavaScript when a seek operation starts on audio or video — useful for showing loading states, disabling controls, and preparing UI before the new playback position is ready.

Pair it with onseeked, read media.seeking for state, and use addEventListener in production code.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about onseeking

Bookmark these before wiring seek-start handlers.

5
Core concepts
▶️ 02

Media only

audio / video.

Scope
🔄 03

.seeking

true / false.

API
04

+ onseeked

Seek end.

Pair
05

Not timeupdate

Seek vs play.

Gotcha

❓ Frequently Asked Questions

It runs JavaScript when the seeking event fires — when a seek operation starts on audio or video.
When the user starts dragging the seek bar, or when JavaScript sets currentTime and the browser begins moving to the new position.
onseeking fires when seeking starts. onseeked fires when seeking finishes and the new position is ready.
Read media.seeking — it is true while a seek operation is in progress.
media.addEventListener("seeking", handler) is preferred in production — easier to attach multiple listeners and pair with seeked.
Yes in all modern browsers that support HTML5 audio and video seeking.

Build responsive media players

Practice the onseeking attribute with seek-start feedback and paired seeked handlers in the Try It editor.

Try video seek example →

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.

5 people found this page helpful