👀 Live Preview
Play the video — status tracks waiting and playing (throttle network in DevTools to test):
Ready — press play

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.
Inline JS.
Buffering.
Media only.
Play vs fetch.
Clear spinner.
Preferred way.
onwaiting AttributeThe 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.
onwaiting is an automatic playback pause while data catches up. onpause fires when the user clicks pause or script calls media.pause().
Set onwaiting on <audio> or <video>, or assign element.onwaiting in JavaScript:
<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>waiting event fires.<audio> and <video> elements.element.onwaiting in script.addEventListener("waiting", handler).onplaying to clear buffering indicators.The onwaiting attribute accepts a string of JavaScript code:
onwaiting="handleWaiting()" — Call a named function.onwaiting="showBufferSpinner()" — Show buffering UI.video.onwaiting = () => { … } — property assignment.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");
});| Property / API | When it runs | Notes |
|---|---|---|
waiting | Playback paused for buffer | onwaiting |
playing | Playback resumed | Clear buffering UI |
stalled | Media fetch stuck | onstalled |
progress | Data downloading | onprogress |
pause | User/script paused | onpause |
readyState | Read anytime | Buffer readiness code |
| Element | Supported? | Notes |
|---|---|---|
<audio> | Yes | Remote audio sources |
<video> | Yes | Remote video sources |
<source> | No | Put handler on parent media element |
<form> | No | Media playback event only |
Local blob: URLs | Rare | Waiting usually needs network fetch |
onwaiting vs onstalled vs onplaying vs onpause| Handler | When it fires | Typical use |
|---|---|---|
onwaiting | Playback paused for buffer | Buffering spinner |
onplaying | Playback resumed after wait | Hide spinner |
onstalled | Download unexpectedly stops | Connection warning |
onpause | User or script paused | Play/pause button state |
Inline video handler, dynamic audio assignment, and waiting + playing status pair for buffering UX.
Play the video — status tracks waiting and playing (throttle network in DevTools to test):
Ready — press play
Show feedback when playback waits for buffered data:
<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>When playback cannot continue because the buffer is empty, the waiting event fires and runs handleWaiting(). Clear the message on playing.
Assign the handler on an audio element at runtime:
<script>
document.getElementById("dynamicAudio").onwaiting = function () {
log.textContent = "Audio is waiting for data.";
};
</script>Assigning element.onwaiting is equivalent to the inline attribute. Attach after the media element exists in the DOM.
Show buffering, then clear when playback resumes:
media.addEventListener("waiting", function () {
status.textContent = "Buffering…";
status.setAttribute("aria-busy", "true");
});
media.addEventListener("playing", function () {
status.textContent = "Playing";
status.removeAttribute("aria-busy");
});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.
aria-live="polite" and aria-busy="true" on status text during waiting.aria-busy when playing fires.Data runs low.
Playback pauses.
onwaiting runs.
Clear on playing.
The waiting event and onwaiting handler are supported in all modern browsers on HTML5 audio and video elements.
onwaiting supportAll major browsers fire waiting when playback pauses for buffering.
Bottom line: Reliable for buffering UX on HTML5 media in all modern browsers.
waitingonplaying to hide the spinneraddEventListener("waiting", …) in productionaria-live and aria-busy for screen readerswaiting with stalled or pausealert() on every buffer pauseplayingonwaiting on non-media elementsThe 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.
onwaitingBookmark these before wiring buffering handlers.
Playback wait.
Whenaudio / video.
ScopePlay vs fetch.
CompareClear spinner.
PairUser pause.
Gotchawaiting 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.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.Practice the onwaiting attribute with video and audio buffering demos in the Try It editor.
5 people found this page helpful