HTML onwaiting Attribute

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

Introduction

The onwaiting attribute is an inline event handler that runs JavaScript when the waiting event fires on an audio or video element. It runs when playback pauses because the next frame is not available — the player has consumed its buffer and is waiting for more data to download. Use it to show a “Buffering…” spinner or message, then clear it on onplaying. This is different from onstalled (download stuck) and onpause (user paused). Prefer addEventListener("waiting", …) in production.

What You’ll Learn

01

Event handler

Inline JS.

02

waiting

Buffering.

03

audio / video

Media only.

04

vs onstalled

Play vs fetch.

05

+ onplaying

Clear spinner.

06

addEventListener

Preferred way.

Purpose of onwaiting Attribute

The primary purpose of onwaiting is to react when playback stops temporarily for buffering — so your page can show a loading indicator, disable seek controls, or reassure users that content is still loading rather than frozen.

The waiting event fires when the media element cannot keep playing because data has not arrived fast enough. When enough data buffers again, playing fires and playback resumes. Always pair onwaiting with onplaying to hide the buffering UI.

💡
Not the same as onpause

onwaiting is an automatic playback pause while data catches up. onpause fires when the user clicks pause or script calls media.pause().

📝 Syntax

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

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

<script>
  media.onwaiting = handleWaiting;
  media.addEventListener("waiting", handleWaiting);
  media.addEventListener("playing", clearBufferingUI);
</script>

Syntax Rules

  • Value is JavaScript executed when the waiting event fires.
  • Valid on <audio> and <video> elements.
  • Fires when playback stops because buffered data ran out.
  • May fire multiple times during playback on slow connections.
  • Also assignable as element.onwaiting in script.
  • Modern alternative: addEventListener("waiting", handler).
  • Pair with onplaying to clear buffering indicators.

💎 Values

The onwaiting attribute accepts a string of JavaScript code:

  • onwaiting="handleWaiting()" — Call a named function.
  • onwaiting="showBufferSpinner()" — Show buffering UI.
  • JavaScript: video.onwaiting = () => { … } — property assignment.
onwaiting-handler.js
function handleWaiting() {
  status.textContent = "Buffering…";
  status.setAttribute("aria-busy", "true");
}

media.addEventListener("waiting", handleWaiting);
media.addEventListener("playing", function () {
  status.textContent = "Playing";
  status.removeAttribute("aria-busy");
});

⚡ Quick Reference

Property / APIWhen it runsNotes
waitingPlayback paused for bufferonwaiting
playingPlayback resumedClear buffering UI
stalledMedia fetch stuckonstalled
progressData downloadingonprogress
pauseUser/script pausedonpause
readyStateRead anytimeBuffer readiness code

Applicable Elements

ElementSupported?Notes
<audio>YesRemote audio sources
<video>YesRemote video sources
<source>NoPut handler on parent media element
<form>NoMedia playback event only
Local blob: URLsRareWaiting usually needs network fetch

onwaiting vs onstalled vs onplaying vs onpause

HandlerWhen it firesTypical use
onwaitingPlayback paused for bufferBuffering spinner
onplayingPlayback resumed after waitHide spinner
onstalledDownload unexpectedly stopsConnection warning
onpauseUser or script pausedPlay/pause button state

Examples Gallery

Inline video handler, dynamic audio assignment, and waiting + playing status pair for buffering UX.

👀 Live Preview

Play the video — status tracks waiting and playing (throttle network in DevTools to test):

Ready — press play

Example — onwaiting on video

Show feedback when playback waits for buffered data:

video-onwaiting.html
<video controls onwaiting="handleWaiting()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status" aria-live="polite"></p>

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

How It Works

When playback cannot continue because the buffer is empty, the waiting event fires and runs handleWaiting(). Clear the message on playing.

Dynamic Values with JavaScript

Assign the handler on an audio element at runtime:

dynamic-onwaiting.html
<script>
  document.getElementById("dynamicAudio").onwaiting = function () {
    log.textContent = "Audio is waiting for data.";
  };
</script>
Try It Yourself

How It Works

Assigning element.onwaiting is equivalent to the inline attribute. Attach after the media element exists in the DOM.

Example — Waiting and playing status

Show buffering, then clear when playback resumes:

waiting-playing-pair.html
media.addEventListener("waiting", function () {
  status.textContent = "Buffering…";
  status.setAttribute("aria-busy", "true");
});

media.addEventListener("playing", function () {
  status.textContent = "Playing";
  status.removeAttribute("aria-busy");
});
Try It Yourself

How It Works

Buffering is often brief. When data arrives and playback resumes, playing fires — reset your UI so users are not stuck on an old “Buffering…” message.

♿ Accessibility

  • Announce buffering — Use aria-live="polite" and aria-busy="true" on status text during waiting.
  • Clear on resume — Remove aria-busy when playing fires.
  • Do not rely on color alone — Pair spinner colors with text like “Buffering…”
  • Keyboard access — Native controls remain usable during buffering.
  • Avoid alert() — Blocking dialogs during buffering harm UX and accessibility.

🧠 How onwaiting Works

1

Playback consumes buffer

Data runs low.

Play
2

Next frame unavailable

Playback pauses.

Wait
3

waiting fires

onwaiting runs.

Event
=

Show buffering UX

Clear on playing.

Browser Support

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

HTML5 Media · Fully supported

Universal onwaiting support

All major browsers fire waiting when playback pauses for buffering.

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
onwaiting attribute 99% supported

Bottom line: Reliable for buffering UX on HTML5 media in all modern browsers.

💡 Best Practices

✅ Do

  • Show a clear “Buffering…” message on waiting
  • Pair with onplaying to hide the spinner
  • Use addEventListener("waiting", …) in production
  • Use aria-live and aria-busy for screen readers
  • Test with DevTools network throttling

❌ Don’t

  • Confuse waiting with stalled or pause
  • Show alert() on every buffer pause
  • Leave buffering UI visible after playing
  • Put onwaiting on non-media elements
  • Assume waiting always means a network error

Conclusion

The onwaiting attribute runs JavaScript when playback pauses for buffering on audio or video — useful for spinners, status messages, and better media UX on slow connections.

Pair it with onplaying, distinguish it from onstalled and onpause, and use addEventListener in production.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about onwaiting

Bookmark these before wiring buffering handlers.

5
Core concepts
▶️ 02

Media only

audio / video.

Scope
03

vs onstalled

Play vs fetch.

Compare
🔄 04

+ onplaying

Clear spinner.

Pair
05

Not onpause

User pause.

Gotcha

❓ Frequently Asked Questions

It runs JavaScript when the waiting event fires — when playback stops because the next frame of media is not available and the player is waiting for more buffered data.
onwaiting means playback paused while waiting for buffer. onstalled means media data download stopped unexpectedly during fetch.
Open DevTools, set network to “Slow 3G,” then play remote audio or video. The waiting event may fire when the buffer runs low.
playing is the most direct signal that playback resumed after waiting. canplay also works but may fire before visible playback restarts.
media.addEventListener("waiting", handler) is preferred in production — easier to pair with playing and other media events.
Yes in all modern browsers that support HTML5 audio and video.

Build better buffering UX

Practice the onwaiting attribute with video and audio buffering demos in the Try It editor.

Try video buffering 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