HTML onstalled Attribute

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

Definition and Usage

The onstalled attribute handles the media stalled event. It fires when the browser is trying to fetch media data, but data is unexpectedly not forthcoming.

Use it on <video> or <audio> to show a network warning. Related: onwaiting (playback needs data), onsuspend (download intentionally paused), onprogress. Prefer addEventListener("stalled", …).

Baseline · Widely available.

Stable across modern browsers since about July 2015. Not deprecated. Not cancelable; does not bubble.

Hard to force on fast networks.

Cached or local files rarely stall. Real stalls need a slow or interrupted fetch. The live preview includes a Simulate option for studying the handler.

Inline handlers discouraged.

MDN: prefer addEventListener over inline on* attributes. Study onstalled to recognize it in markup.

HTML Syntax

syntax.html
<video onstalled=" script">

script runs when media fetch stalls. Same idea on <audio>. Preferred: element.addEventListener("stalled", handler).

Attribute Values

How you listen for media stalled:

Value / formDescriptionTry it
JavaScript on mediaInline handler, e.g. showStall()Try it
addEventListener("stalled")Preferred modern listenerTry it
With related eventsLog stalled beside waiting / suspendTry it

Live Preview

Load a clip (may not stall on a fast connection), or simulate stalled to practice the handler.

action

Uses /video/count.mp4. Simulate dispatches stalled for study when the network does not stall.

Demo

Ready. Click Load video or Simulate stalled.

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer listeners in real apps.

Example 1 — Inline onstalled on video

Recognize the attribute form. Simulate if your network never stalls.

HTML
<video
  id="clip"
  width="280"
  controls
  onstalled="document.getElementById('status').textContent = 'stalled — data not arriving.'"
></video>
<p id="status">Idle</p>
<button type="button" id="go">Load video</button>
<button type="button" id="sim">Simulate stalled</button>

<script>
  var video = document.getElementById("clip");
  document.getElementById("go").addEventListener("click", function () {
    document.getElementById("status").textContent = "Loading…";
    video.src = "/video/count.mp4?t=" + Date.now();
    video.load();
  });
  document.getElementById("sim").addEventListener("click", function () {
    video.dispatchEvent(new Event("stalled"));
  });
</script>
Try It Yourself

How It Works

  1. onstalled registers an inline media handler.
  2. Load starts a real fetch (may or may not stall).
  3. Simulate dispatches stalled so you can see the handler.
  4. Status updates when the event runs.

Example 2 — Preferred addEventListener

Same event with a clean script listener (MDN-style message).

HTML
<video id="clip" width="280" controls></video>
<p id="status">Idle</p>
<button type="button" id="go">Load video</button>
<button type="button" id="sim">Simulate stalled</button>

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

  video.addEventListener("stalled", function () {
    status.textContent = "Failed to fetch data, but trying.";
  });

  document.getElementById("go").addEventListener("click", function () {
    status.textContent = "Loading…";
    video.src = "/video/count.mp4?t=" + Date.now();
    video.load();
  });

  document.getElementById("sim").addEventListener("click", function () {
    video.dispatchEvent(new Event("stalled"));
  });
</script>
Try It Yourself

How It Works

  1. Listener on video — no inline attribute.
  2. Message matches MDN’s “trying, but data not arriving” idea.
  3. Load exercises a real network path when possible.
  4. Simulate keeps the lesson reliable in class demos.

Example 3 — stalled vs waiting vs suspend

Log related media events so the differences are easy to see.

HTML
<video id="clip" width="280" controls></video>
<pre id="log"></pre>
<button type="button" id="go">Load video</button>
<button type="button" id="sim">Simulate stalled</button>

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

  function add(type) {
    log.textContent += type + "\n";
  }

  video.addEventListener("stalled", function () { add("stalled"); });
  video.addEventListener("waiting", function () { add("waiting"); });
  video.addEventListener("suspend", function () { add("suspend"); });
  video.addEventListener("progress", function () { add("progress"); });

  document.getElementById("go").addEventListener("click", function () {
    log.textContent = "";
    video.src = "/video/count.mp4?t=" + Date.now();
    video.load();
  });

  document.getElementById("sim").addEventListener("click", function () {
    video.dispatchEvent(new Event("stalled"));
  });
</script>
Try It Yourself

How It Works

  1. stalled — fetch trying, data not arriving.
  2. waiting — playback paused for more data.
  3. suspend — download intentionally stopped.
  4. progress — download pulses when bytes do arrive.

Edge Cases & Pitfalls

Most confusion is mixing stalled with waiting or expecting it on every load.

network

Not guaranteed on every load

Healthy, fast, or cached media may never fire stalled. That is normal.

vs wait

stalled ≠ waiting

waiting is about playback needing data. stalled is about the fetch not delivering.

vs suspend

stalled ≠ suspend

suspend means the UA stopped downloading on purpose. stalled means it is still trying.

target

Listen on the media element

Does not bubble. Put the handler on <video> / <audio>.

style

Prefer listeners

Inline on* attributes mix concerns. Use addEventListener in production code.

Browser Support

onstalled is a media event handler for unexpected media fetch stalls. Prefer addEventListener in apps.

✓ Baseline · Widely available

onstalled

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the media stalled event.

97% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer 9+
Supported*
stalled Widely supported

Bottom line: *Safe on modern browsers. When demos do not stall, simulate the event to study the handler.

Key Takeaways

  • Role: media fetch is trying, but data is not arriving.
  • Compare: waiting (playback) / suspend (stopped on purpose).
  • Target: <video> / <audio> (no bubbling).
  • Demos: may need Simulate on fast/cached media.

One line: onstalled means the media fetch is stuck waiting for data — show a network hint, and do not confuse it with waiting or suspend.

Frequently Asked Questions

It is an event handler for the stalled event on media elements. That event fires when the browser is trying to fetch media data, but data is unexpectedly not forthcoming.
stalled is about the download/fetch not delivering data as expected. waiting fires when playback pauses because it needs more data. They often appear in related network-delay situations, but answer different questions.
suspend means the browser intentionally stopped downloading (for example enough data is buffered). stalled means the agent is still trying, but data is not arriving.
Fast or cached files rarely stall. Real stalls need a slow, interrupted, or hanging network response. Use Simulate in the live preview to practice the handler.
No. It is not cancelable and does not bubble. Listen on the <video> or <audio> element itself.
Prefer addEventListener("stalled", handler). MDN discourages inline HTML event handler attributes.

Next: onstorage

React when another document changes Web Storage.

onstorage 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