HTML onsuspend Attribute

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

Introduction

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.

What You’ll Learn

01

Event handler

Inline JS.

02

suspend

Load paused.

03

audio / video

Media only.

04

vs onstalled

Normal vs error.

05

preload

Fetch limits.

06

addEventListener

Preferred way.

Purpose of onsuspend Attribute

The 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.

💡
Not playback pause

onsuspend means data loading paused. If the user clicks pause, the pause event fires (onpause). Playback can continue while loading is suspended.

📝 Syntax

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

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

<script>
  media.onsuspend = handleSuspend;
  media.addEventListener("suspend", handleSuspend);
</script>

Syntax Rules

  • Value is JavaScript executed when the suspend event fires.
  • Valid on <audio> and <video> elements.
  • Fires when media data loading is intentionally suspended by the browser.
  • Often fires multiple times during a single load/play session.
  • Also assignable as element.onsuspend in script.
  • Modern alternative: addEventListener("suspend", handler).
  • Not the same as onpause (user pause) or onstalled (network stall).

💎 Values

The onsuspend attribute accepts a string of JavaScript code:

  • onsuspend="handleSuspend()" — Call a named function.
  • onsuspend="logLoadingState()" — Update a loading status label.
  • JavaScript: video.onsuspend = () => { … } — property assignment.
onsuspend-handler.js
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");
});

⚡ Quick Reference

Property / APIWhen it runsNotes
suspendBrowser pauses data fetchonsuspend
progressData is downloadingonprogress
stalledFetch stuck unexpectedlyonstalled
waitingPlayback paused for bufferonwaiting
pauseUser or script paused playbackonpause
networkStateRead anytimeNETWORK_IDLE when suspended

Applicable Elements

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

onsuspend vs onstalled vs onpause vs onwaiting

HandlerWhen it firesTypical use
onsuspendBrowser pauses data loading (normal)Loading state, analytics
onstalledDownload unexpectedly stopsConnection warning
onpausePlayback pausedPlay/pause UI
onwaitingPlayback waiting for bufferBuffering spinner

Examples Gallery

Inline video handler, dynamic audio assignment, and suspend + progress status pair.

👀 Live Preview

Play the video — status tracks progress, suspend, and playing:

Ready — press play

Example — onsuspend on video

Run a function when media data loading suspends:

video-onsuspend.html
<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>
Try It Yourself

How It Works

When the browser decides it has enough buffered data (or preload limits apply), the suspend event fires and runs handleSuspend().

Dynamic Values with JavaScript

Assign the handler on an audio element at runtime:

dynamic-onsuspend.html
<script>
  document.getElementById("dynamicAudio").onsuspend = function () {
    log.textContent = "Data loading suspended by the browser.";
  };
</script>
Try It Yourself

How It Works

Assigning element.onsuspend is equivalent to the inline attribute. Use preload="metadata" to see suspend fire early in some browsers.

Example — Suspend and progress status

Pair loading events for clearer buffer UX:

suspend-progress-pair.html
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";
});
Try It Yourself

How It Works

Suspend often alternates with progress as the browser fetches in chunks. Together they describe the media loading lifecycle better than either event alone.

♿ Accessibility

  • Do not alarm users on suspend — Suspend is usually normal; avoid error-style messaging unless paired with stalled or error.
  • Loading state — Use aria-busy or aria-live="polite" only when playback is actually waiting (waiting event).
  • Keep controls usable — Suspend does not disable native play/pause buttons.
  • Captions — Suspend affects data fetch, not caption tracks already loaded.
  • Avoid alert() — Use visible status text for loading feedback.

🧠 How onsuspend Works

1

Media starts loading

progress fires.

Fetch
2

Enough buffered

Browser pauses fetch.

Idle
3

suspend fires

onsuspend runs.

Event
=

Normal pause

Not a network error.

Browser Support

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

HTML5 Media · Fully supported

Universal onsuspend support

All major browsers fire suspend when media data loading is intentionally paused.

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

Bottom line: Reliable for media loading state in all modern browsers.

💡 Best Practices

✅ Do

  • Pair onsuspend with onprogress for loading UX
  • Use addEventListener("suspend", …) in production
  • Treat suspend as normal bandwidth-saving behavior
  • Use onstalled for unexpected download problems
  • Use correct MIME types (video/mp4, audio/mpeg)

❌ Don’t

  • Confuse suspend with pause or stalled
  • Show “network error” on every suspend event
  • Use alert() for loading feedback
  • Put onsuspend on non-media elements
  • Assume suspend means playback stopped

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about onsuspend

Bookmark these before wiring media load handlers.

5
Core concepts
▶️ 02

Media only

audio / video.

Scope
03

vs onstalled

Normal vs stall.

Compare
📈 04

+ onprogress

Load timeline.

Pair
05

Not onpause

User pause.

Gotcha

❓ Frequently Asked Questions

It runs JavaScript when the suspend 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.
No. User pause fires pause (onpause). suspend is about stopping the download of media bytes, not stopping playback.
When the browser has buffered enough data for current needs, or when 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.
Yes in all modern browsers that support HTML5 audio and video.

Understand media loading events

Practice the onsuspend attribute with video and audio loading demos in the Try It editor.

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