👀 Live Preview
Play the video — status tracks progress, suspend, and playing:
Ready — press play

The onsuspend attribute is an inline event handler that runs JavaScript when the suspend event fires on an audio or video element. It runs when the browser intentionally pauses loading media data — often because enough bytes are buffered for current playback, or because preload limits how much is fetched upfront. This is not the same as the user pausing playback (onpause) or a network stall (onstalled). Use onsuspend to track loading state, log bandwidth-saving behavior, or pair with onprogress for buffer UX. Prefer addEventListener("suspend", …) in production.
Inline JS.
Load paused.
Media only.
Normal vs error.
Fetch limits.
Preferred way.
onsuspend AttributeThe primary purpose of onsuspend is to react when the browser stops fetching more media data — so your page can update loading indicators, analytics, or debug logs. The suspend event is usually normal behavior: the user agent has buffered enough for now and pauses the download to save bandwidth.
It can also fire when preload="none" or preload="metadata" limits initial loading. Do not treat every suspend as a network error — pair with onstalled or onerror for problems.
onsuspend means data loading paused. If the user clicks pause, the pause event fires (onpause). Playback can continue while loading is suspended.
Set onsuspend on <audio> or <video>, or assign element.onsuspend in JavaScript:
<video controls onsuspend="handleSuspend()">
<source src="/video/count.mp4" type="video/mp4">
</video>
<script>
media.onsuspend = handleSuspend;
media.addEventListener("suspend", handleSuspend);
</script>suspend event fires.<audio> and <video> elements.element.onsuspend in script.addEventListener("suspend", handler).onpause (user pause) or onstalled (network stall).The onsuspend attribute accepts a string of JavaScript code:
onsuspend="handleSuspend()" — Call a named function.onsuspend="logLoadingState()" — Update a loading status label.video.onsuspend = () => { … } — property assignment.function handleSuspend() {
status.textContent = "Data loading suspended — buffered enough for now";
status.classList.add("is-suspended");
}
media.addEventListener("suspend", handleSuspend);
media.addEventListener("progress", function () {
status.textContent = "Loading media data…";
status.classList.remove("is-suspended");
});| Property / API | When it runs | Notes |
|---|---|---|
suspend | Browser pauses data fetch | onsuspend |
progress | Data is downloading | onprogress |
stalled | Fetch stuck unexpectedly | onstalled |
waiting | Playback paused for buffer | onwaiting |
pause | User or script paused playback | onpause |
networkState | Read anytime | NETWORK_IDLE when suspended |
| Element | Supported? | Notes |
|---|---|---|
<audio> | Yes | Remote audio sources |
<video> | Yes | Remote video sources |
<source> | No | Put handler on parent media element |
<form> | No | Media loading event only |
Local blob: URLs | Rare | Suspend usually involves network fetch |
onsuspend vs onstalled vs onpause vs onwaiting| Handler | When it fires | Typical use |
|---|---|---|
onsuspend | Browser pauses data loading (normal) | Loading state, analytics |
onstalled | Download unexpectedly stops | Connection warning |
onpause | Playback paused | Play/pause UI |
onwaiting | Playback waiting for buffer | Buffering spinner |
Inline video handler, dynamic audio assignment, and suspend + progress status pair.
Play the video — status tracks progress, suspend, and playing:
Ready — press play
Run a function when media data loading suspends:
<video controls onsuspend="handleSuspend()">
<source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status"></p>
<script>
function handleSuspend() {
document.getElementById("status").textContent =
"Media data loading suspended";
}
</script>When the browser decides it has enough buffered data (or preload limits apply), the suspend event fires and runs handleSuspend().
Assign the handler on an audio element at runtime:
<script>
document.getElementById("dynamicAudio").onsuspend = function () {
log.textContent = "Data loading suspended by the browser.";
};
</script>Assigning element.onsuspend is equivalent to the inline attribute. Use preload="metadata" to see suspend fire early in some browsers.
Pair loading events for clearer buffer UX:
media.addEventListener("progress", function () {
status.textContent = "Loading media data…";
});
media.addEventListener("suspend", function () {
status.textContent = "Loading suspended — enough buffered";
});
media.addEventListener("playing", function () {
status.textContent = "Playing";
});Suspend often alternates with progress as the browser fetches in chunks. Together they describe the media loading lifecycle better than either event alone.
stalled or error.aria-busy or aria-live="polite" only when playback is actually waiting (waiting event).progress fires.
Browser pauses fetch.
onsuspend runs.
Not a network error.
The suspend event and onsuspend handler are supported in all modern browsers on HTML5 audio and video elements.
onsuspend supportAll major browsers fire suspend when media data loading is intentionally paused.
Bottom line: Reliable for media loading state in all modern browsers.
onsuspend with onprogress for loading UXaddEventListener("suspend", …) in productiononstalled for unexpected download problemsvideo/mp4, audio/mpeg)suspend with pause or stalledalert() for loading feedbackonsuspend on non-media elementsThe onsuspend attribute runs JavaScript when the browser pauses loading media data on audio or video — useful for loading indicators, analytics, and understanding buffer behavior.
Remember: suspend is usually normal, not an error. Pair it with onprogress and onstalled, and use addEventListener in production code.
onsuspendBookmark these before wiring media load handlers.
Not playback.
Whataudio / video.
ScopeNormal vs stall.
CompareLoad timeline.
PairUser pause.
Gotchasuspend event fires — when the browser intentionally pauses loading media data, often because enough is buffered.onsuspend is a deliberate pause in data loading (usually normal). onstalled means download stopped unexpectedly, often due to network issues.pause (onpause). suspend is about stopping the download of media bytes, not stopping playback.preload settings limit fetching. It may fire several times during load and play.media.addEventListener("suspend", handler) is preferred in production — easier to pair with progress and other media events.Practice the onsuspend attribute with video and audio loading demos in the Try It editor.
5 people found this page helpful