HTML onwaiting Attribute

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

Definition and Usage

The onwaiting attribute is an event-handler attribute for <audio> and <video>. It runs when the waiting event fires — playback has stopped because of a temporary lack of data (buffering).

The event is not cancelable and does not bubble. Related: onplaying (playback resumes), onstalled (fetch not delivering), onpause (user/script pause — different meaning).

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Hard to force on fast local files.

Short or cached clips rarely buffer. The live preview includes Simulate so you can study the handler without a slow network.

HTML Syntax

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

script runs when playback waits for data. Preferred in apps: media.addEventListener("waiting", handler).

Attribute Values

The attribute value is a script. Common patterns:

Value / patternDescriptionTry it
handler()Show a buffering spinner or status textTry it
addEventListener("waiting")Preferred modern listener on audio/videoTry it
With playingShow spinner on wait; hide when playback continuesTry it
vs stalled / pauseDifferent reasons playback may stopTry it

Live Preview

Play the sample (may not wait on a fast connection), or simulate waiting to practice the handler.

Media

Sample /video/count.mp4 or /audio/count.mp3. Simulate dispatches waiting for study.

Player

Ready — play media or Simulate waiting

HTML Examples

Short study snippets. Use Try It Yourself — Simulate if buffering never happens locally.

Example 1 — Inline onwaiting on Video

Show a buffering message when playback waits for data.

HTML
<video
  id="clip"
  width="400"
  height="225"
  controls
  onwaiting="showWait()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status">Ready</p>
<button type="button" id="sim">Simulate waiting</button>

<script>
  function showWait() {
    document.getElementById("status").textContent =
      "waiting — playback needs more data.";
  }
  document.getElementById("sim").onclick = function () {
    document.getElementById("clip").dispatchEvent(new Event("waiting"));
  };
</script>
Try It Yourself

How It Works

  1. Put onwaiting on the media element — not on <source>.
  2. Playback runs out of buffered data — the browser fires waiting.
  3. Handler updates UI — spinner, “Buffering…”, disable seek, and so on.
  4. Simulate dispatches the same event for study on fast networks.

Example 2 — addEventListener on Audio

Preferred script pattern on an audio element.

HTML
<audio id="clip" controls>
  <source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<p id="log">Idle</p>
<button type="button" id="sim">Simulate waiting</button>

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

  clip.addEventListener("waiting", function () {
    log.textContent = "waiting event — buffering.";
  });
  document.getElementById("sim").onclick = function () {
    clip.dispatchEvent(new Event("waiting"));
  };
</script>
Try It Yourself

How It Works

  1. Select the audio with getElementById.
  2. Register waiting with addEventListener.
  3. When buffering stops playback, update the log.
  4. Simulate helps when the short MP3 never waits.

Example 3 — waiting vs playing

Show a spinner on waiting; clear it when playing resumes.

HTML
<video id="clip" width="400" height="225" controls>
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="state">State: idle</p>
<button type="button" id="sim">Simulate waiting</button>

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

  clip.addEventListener("waiting", function () {
    state.textContent = "State: buffering (waiting)";
  });
  clip.addEventListener("playing", function () {
    state.textContent = "State: playing";
  });
  clip.addEventListener("pause", function () {
    state.textContent = "State: paused";
  });
  document.getElementById("sim").onclick = function () {
    clip.dispatchEvent(new Event("waiting"));
  };
</script>
Try It Yourself

How It Works

  1. waiting — playback stopped for more data (show spinner).
  2. playing — playback is moving again (hide spinner).
  3. pause — user/script pause (not the same as buffering).
  4. UI tip: only treat waiting as “buffering,” not every pause.

Edge Cases & Pitfalls

Most confusion mixes buffering waits with user pauses or network stalls.

pause

waiting ≠ pause

pause is a paused state. waiting means “need more data.” Do not treat every stop as a user pause.

stalled

waiting ≠ stalled

stalled is about the fetch not delivering. waiting is about playback needing data. Listen for both if you show network UI.

local

Local demos rarely wait

Cached files stay buffered. Use Simulate, DevTools throttling, or a large remote file to observe real waits.

bubble

Does not bubble

Attach the listener to the <video> / <audio> element itself.

a11y

Announce buffering to assistive tech

Update an aria-live region (or similar) when waiting/playing so screen reader users know why playback stalled.

Browser Support

onwaiting is an HTML media event handler for the waiting event on audio/video. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

onwaiting

Widely available since about July 2015. Supported across modern browsers for HTML media elements.

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer Legacy support
Supported
onwaiting Widely supported

Bottom line: Safe to use for buffering UI. Prefer addEventListener; pair with playing to clear spinners.

Key Takeaways

  • Role: playback stopped temporarily for more media data.
  • vs pause: buffering wait ≠ user/script pause.
  • Pair: clear UI on playing when playback resumes.
  • Study tip: simulate the event when local files never buffer.

One line: use onwaiting for buffering UI — not for intentional pauses.

Frequently Asked Questions

It is an event-handler attribute on audio or video. When playback stops because of a temporary lack of data (buffering), the waiting event fires and the JavaScript in onwaiting runs.
pause means playback entered the paused state (user or pause()). waiting means playback stopped because more media data is needed — the element is still trying to play once data arrives.
waiting is about playback needing more data. stalled is about the fetch unexpectedly not delivering data. They can both appear during bad networks but answer different questions.
No. It is not cancelable and does not bubble. Listen on the video or audio element itself.
Short or cached files rarely run out of buffer. Real waiting needs a slow stream. Use Simulate in the live preview to practice the handler.
No. The waiting event is Baseline widely available since about July 2015. Prefer media.addEventListener("waiting", handler) in apps.

Next: onwheel

Handle the standard mouse-wheel / trackpad scroll event.

onwheel tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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