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

The onstalled attribute is an inline event handler that runs JavaScript when the stalled event fires on an audio or video element. It runs when the browser is trying to fetch media data but data is not arriving for an unexpectedly long time — often due to a slow or interrupted network connection during download or buffering. Use it to show a “connection problem” message, offer a retry button, or log analytics. Pair with onwaiting and onplaying for full buffering UX. Prefer addEventListener("stalled", …) in production.
Inline JS.
Fetch stuck.
Media only.
Download vs play.
Retry UX.
Preferred way.
onstalled AttributeThe primary purpose of onstalled is to react when media data download stalls — so your page can inform the user, suggest checking their connection, or attempt recovery instead of leaving them with a frozen player and no explanation.
The stalled event fires on the media element when the user agent is actively trying to fetch data but none is forthcoming. It is related to network buffering issues, not the same as error (fatal load failure) or ended (playback finished).
onstalled means data download stopped unexpectedly. onwaiting means playback paused while waiting for more buffered data. Use both for complete buffering feedback.
Set onstalled on <audio> or <video>, or assign element.onstalled in JavaScript:
<audio controls onstalled="handleStalled()">
<source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<script>
media.onstalled = handleStalled;
media.addEventListener("stalled", handleStalled);
</script>stalled event fires.<audio> and <video> elements.element.onstalled in script.addEventListener("stalled", handler).onerror for unrecoverable load failures.The onstalled attribute accepts a string of JavaScript code:
onstalled="handleStalled()" — Call a named function.onstalled="showRetryMessage()" — Show connection help text.audio.onstalled = () => { … } — property assignment.function handleStalled() {
status.textContent = "Download stalled — check your connection";
status.classList.add("is-stalled");
}
media.addEventListener("stalled", handleStalled);
media.addEventListener("playing", function () {
status.textContent = "Playing";
status.classList.remove("is-stalled");
});| Property / API | When it runs | Notes |
|---|---|---|
stalled | Media fetch stops unexpectedly | onstalled |
waiting | Playback paused for data | onwaiting |
progress | Data downloading | onprogress |
error | Load failed | onerror |
networkState | Read anytime | Network status code |
| Element | Supported? | Notes |
|---|---|---|
<audio> | Yes | Remote audio sources |
<video> | Yes | Remote video sources |
<source> | No | Put handler on parent media element |
Local blob: URLs | Rare | Stalled usually needs network fetch |
<iframe> | No | Embedded players are separate documents |
onstalled vs onwaiting vs onprogress vs onerror| Handler | When it fires | Typical use |
|---|---|---|
onprogress | Data is downloading | Buffer progress bar |
onstalled | Download unexpectedly stops | Connection warning, retry |
onwaiting | Playback paused for buffer | Loading spinner |
onerror | Media failed to load | Error message, fallback |
Inline audio handler, dynamic assignment, and stalled + playing status pair for buffering UX.
Play the audio — status tracks stalled and playing events (throttle network in DevTools to test):
Ready — press play
Run a function when media download stalls:
<audio controls onstalled="handleStalled()">
<source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<p id="status"></p>
<script>
function handleStalled() {
document.getElementById("status").textContent =
"Audio loading has stalled!";
}
</script>When the browser tries to fetch audio data but none arrives for an unexpectedly long time, the stalled event fires and runs handleStalled().
Assign the handler on an audio element at runtime:
<script>
document.getElementById("dynamicAudio").onstalled = function () {
log.textContent = "Media download stalled. Please try again.";
};
</script>Assigning element.onstalled is equivalent to the inline attribute. Use this when you attach the handler after the DOM loads.
Clear stalled warning when playback resumes:
media.addEventListener("stalled", function () {
status.textContent = "Download stalled";
status.setAttribute("aria-busy", "true");
});
media.addEventListener("playing", function () {
status.textContent = "Playing";
status.removeAttribute("aria-busy");
});Stalled may be temporary. When data arrives and playback resumes, playing fires — reset your UI so users are not stuck on an old warning.
aria-live="polite" on status text when download stalls.Fetch begins.
Network issue.
onstalled runs.
Message, retry, analytics.
The stalled event and onstalled handler are supported in all modern browsers on HTML5 audio and video elements.
onstalled supportAll major browsers fire stalled when media data fetch stops unexpectedly.
Bottom line: Reliable for stall handling on HTML5 media in all modern browsers.
stalled firesonplaying to clear warnings when data resumesaddEventListener("stalled", …) in productionstalled with waiting or erroralert() on every stallonstalled on non-media elementsaudio/mpeg not audio/mp3)The onstalled attribute runs JavaScript when media data download stalls unexpectedly on audio or video — useful for connection warnings, retry buttons, and better buffering UX.
Pair it with onwaiting and onplaying, use addEventListener in production, and test on slow networks to verify your handlers behave correctly.
onstalledBookmark these before wiring stall handlers.
No data.
Whenaudio / video.
ScopePlayback pause.
CompareClear warning.
PairMay recover.
Gotchastalled event fires — when the browser is fetching media data but no data arrives for an unexpectedly long time.onstalled means media data download stopped unexpectedly. onwaiting means playback paused while waiting for more buffered data.onerror for fatal failures and clear stall warnings on playing when data resumes.media.addEventListener("stalled", handler) is preferred in production — easier to attach multiple listeners and pair with other media events.Practice the onstalled attribute with connection warnings and recovery UX in the Try It editor.
5 people found this page helpful