HTML onsuspend Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The onsuspend attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the suspend event fires — the user agent is intentionally not fetching media data, and networkState is NETWORK_IDLE.

That can mean there is no more data to load, or loading is unnecessary for now (for example the browser only buffers a few minutes ahead). The event is not cancelable and does not bubble. Related: onstalled, onwaiting, preload, and oncanplay.

Baseline · Widely available.

Not deprecated and not experimental. The suspend event is stable across modern browsers since about July 2015.

Prefer addEventListener in apps.

Inline onsuspend is fine for learning. Production code usually uses media.addEventListener("suspend", handler). Do not confuse this with onpause (playback paused).

HTML Syntax

syntax.html
<video|audio onsuspend=" script">

script is JavaScript that runs when suspend fires. Equivalent JS: media.onsuspend = handler or media.addEventListener("suspend", handler).

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript when media data fetch is suspendedTry it
onsuspend="fn()"Call a named function from the attributeTry it
addEventListener("suspend")Preferred modern listener; often log networkStateTry it
With load eventsCompare suspend vs waiting / stalledTry it
+ preloadPreload policy affects when fetch starts/stopsTry it

Live Preview

Load sample media. Short clips often fire suspend once buffering settles.

Media

Sample /video/count.mp4 or /audio/count.mp3. Watch the status for suspend.

Player

Loading…

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline onsuspend on Video

Update status when the browser stops fetching for now.

HTML
<video width="400" height="225" controls preload="auto" onsuspend="onSuspended()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status">Waiting for suspend…</p>

<script>
  function onSuspended() {
    document.getElementById("status").textContent =
      "suspend — media fetch idle (NETWORK_IDLE).";
  }
</script>
Try It Yourself

How It Works

  1. Put onsuspend on the media element — here <video>.
  2. Browser loads media — then may stop fetching intentionally.
  3. networkState becomes idle — suspend fires.
  4. Handler updates UI — e.g. hide a “buffering download” indicator.

Example 2 — addEventListener + networkState

Preferred script pattern; show the numeric network state.

HTML
<audio id="clip" controls preload="auto">
  <source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<p id="log">Idle</p>

<script>
  document.getElementById("clip").addEventListener("suspend", function () {
    document.getElementById("log").textContent =
      "suspend — networkState = " + this.networkState;
  });
</script>
Try It Yourself

How It Works

  1. Select the audio with getElementById.
  2. Register suspend with addEventListener.
  3. When idle, read networkState (NETWORK_IDLE is 1).
  4. Update the log for the student to see.

Example 3 — suspend vs waiting vs stalled

Log the three network-related events beginners mix up.

HTML
<video id="clip" width="400" height="225" controls preload="auto">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="state">Last event: —</p>

<script>
  var clip = document.getElementById("clip");
  var state = document.getElementById("state");

  clip.addEventListener("suspend", function () {
    state.textContent = "Last event: suspend (fetch idle on purpose)";
  });
  clip.addEventListener("waiting", function () {
    state.textContent = "Last event: waiting (need more data to play)";
  });
  clip.addEventListener("stalled", function () {
    state.textContent = "Last event: stalled (trying to fetch, no data)";
  });
</script>
Try It Yourself

How It Works

  1. suspend — browser chose not to fetch more (idle).
  2. waiting — playback needs more data.
  3. stalled — fetch attempted but data is not arriving.
  4. Local short clips often show suspend and rarely stalled — that’s normal.

Edge Cases & Pitfalls

Most confusion is treating suspend like “playback paused” or like a network error.

vs pause

Not the same as pause

onpause means playback stopped. suspend means download is idle — the video may still be playing from the buffer.

intentional

Intentional idle, not failure

Browsers may buffer only part of a long file, then suspend until more is needed. That is expected, not an error.

stalled

Do not confuse with stalled

stalled is “trying to get data and not getting it.” suspend is “not fetching on purpose.”

bubble

Does not bubble

Listen on the audio/video element itself. Parent listeners will not see a bubbling suspend.

property

.onsuspend = replaces listeners

Assigning the IDL property overwrites a previous assignment. Prefer addEventListener for multiple handlers.

Browser Support

onsuspend is an HTML event-handler attribute for media elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

onsuspend

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the suspend event on audio and video.

97% Global support (approx.)
Google Chrome 3+
Full support
Mozilla Firefox 3.5+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 10.5+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 9+
Supported
onsuspend Widely supported

Bottom line: Safe to use for media network UI. Prefer addEventListener in production, and pair with waiting/stalled when you need buffering or error-style feedback.

Key Takeaways

  • Role: run script when media data fetch is intentionally idle.
  • State: networkState is NETWORK_IDLE.
  • Not pause: playback can continue while download is suspended.
  • Contrast: waiting / stalled for need-data or failed fetch.

One line: onsuspend means “the browser stopped downloading media on purpose” — idle network, not the same as pausing playback.

Frequently Asked Questions

It is an event-handler attribute on audio or video. The suspend event fires when the browser intentionally is not fetching media data — networkState becomes NETWORK_IDLE. That can mean buffering is done for now, or there is nothing more to load.
The HTML audio and video elements. Put the handler on the media element itself.
No. pause means playback stopped (paused is true). suspend means the user agent stopped downloading media data on purpose — playback may still be playing from the buffer.
stalled means the browser is trying to fetch data but is not receiving it. waiting means playback stopped temporarily for more data. suspend means the browser chose not to fetch more right now (idle).
Both work. For learning, onsuspend in HTML is fine. In production code, prefer media.addEventListener("suspend", handler).
No. The suspend event and onsuspend handler are standard HTML media features and Baseline widely available since about July 2015.

Next: ontimeupdate

React as currentTime changes during media playback.

ontimeupdate tutorial →

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.

8 people found this page helpful