HTML onprogress Attribute

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

Definition and Usage

The onprogress attribute handles the media progress event. It fires periodically while the browser downloads a <video> or <audio> resource.

Use it to update a “loading…” label or estimate buffered amount via media.buffered. Related readiness events: oncanplay, onloadeddata. Prefer addEventListener("progress", …).

Baseline · Widely available.

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

Inline handlers discouraged.

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

HTML Syntax

syntax.html
<video onprogress=" script">

script runs as download progress updates. Same idea on <audio>. Preferred: element.addEventListener("progress", handler).

Attribute Values

How you listen for media progress:

Value / formDescriptionTry it
JavaScript on mediaInline handler, e.g. showLoad()Try it
addEventListener("progress")Preferred listener + buffered estimateTry it
With other media eventsLog progress beside canplayTry it

Live Preview

Load a short video. Status updates when progress fires (and when playback can start).

action

Uses /video/count.mp4. Cached files may fire few progress events — that is normal.

Demo

Ready. Click Load video.

HTML Examples

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

Example 1 — Inline onprogress on video

Recognize the attribute form. Loading the file updates the status line.

HTML
<video
  id="clip"
  width="280"
  controls
  onprogress="document.getElementById('status').textContent = 'progress fired.'"
></video>
<p id="status">Idle</p>
<button type="button" id="go">Load video</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();
  });
</script>
Try It Yourself

How It Works

  1. onprogress registers an inline media handler.
  2. Load sets src and calls load().
  3. As bytes arrive, the browser fires progress periodically.
  4. Status confirms the handler ran (may be brief if cached).

Example 2 — Preferred listener + buffered

Estimate how much of the media timeline is already downloaded.

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

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

  video.addEventListener("progress", function () {
    if (video.buffered.length > 0 && video.duration > 0) {
      var end = video.buffered.end(video.buffered.length - 1);
      var pct = Math.round((end / video.duration) * 100);
      status.textContent = "Buffered ~" + pct + "%";
    } else {
      status.textContent = "progress (buffered not ready yet)";
    }
  });

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

How It Works

  1. Listener runs on each progress pulse.
  2. buffered holds time ranges already downloaded.
  3. end / duration ≈ fraction loaded (when duration is known).
  4. UI tip: show “loading” text even before a percentage exists.

Example 3 — progress beside canplay

See download pulses vs “enough data to start.”

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

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

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

  video.addEventListener("progress", function () { add("progress"); });
  video.addEventListener("canplay", function () { add("canplay"); });

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

How It Works

  1. progress may fire many times during download.
  2. canplay fires once enough data exists to begin playback.
  3. Log makes the sequence easy to study.
  4. Cache: a warm cache can shorten or skip some pulses.

Edge Cases & Pitfalls

Progress is about download pulses — not a guaranteed smooth percent meter.

cache

Few events when cached

From cache, progress may fire once or barely at all. Append a cache-bust query in demos if you need to see pulses.

buffered

Duration may be unknown early

Do not divide by duration until it is a finite number. Check buffered.length first.

vs ready

Not the same as canplay

progress = downloading. canplay = enough to start. Use both when building loaders.

bubble

Does not bubble

Listen on the media element itself. A parent onprogress will not see child media progress.

style

Prefer listeners

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

Browser Support

onprogress is a media event handler for download progress on video/audio. Prefer addEventListener in apps.

✓ Baseline · Widely available

onprogress

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the media progress 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*
progress Widely supported

Bottom line: *Safe on modern browsers. Frequency of progress events varies with network and cache.

Key Takeaways

  • Role: periodic updates while media downloads.
  • Estimate: use buffered + duration carefully.
  • Target: <video> / <audio>, not parents.
  • Pair with: canplay for “ready to start.”

One line: onprogress tracks media download pulses — read buffered for an estimate, listen on the media element.

Frequently Asked Questions

It is an event handler for the progress event on media elements. That event fires periodically while the browser downloads a video or audio resource.
On HTMLMediaElement targets such as <video> and <audio>. Prefer element.addEventListener("progress", handler) in modern code.
Read media.buffered. When buffered.length > 0 and duration is known, buffered.end(buffered.length - 1) / duration gives an approximate loaded fraction.
No. It is not cancelable and does not bubble.
progress fires repeatedly while bytes download. canplay fires when enough data exists to start playback. They answer different questions: “how much loaded?” vs “can I start?”
Prefer addEventListener("progress", handler). MDN discourages inline HTML event handler attributes.

Next: onratechange

React when media playback speed changes.

onratechange 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