HTML onloadeddata Attribute

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

Definition and Usage

The onloadeddata attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the loadeddata event fires — the media data for the current playback position has finished loading (often the first frame).

That usually means readyState reached HAVE_CURRENT_DATA (or greater) for the first time. It comes after onloadedmetadata and typically before or alongside oncanplay.

Baseline · Widely available.

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

Data-saver may skip it.

MDN: on some mobile/tablet browsers with data-saver enabled, loadeddata may not fire. Do not rely on it alone for critical UI.

HTML Syntax

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

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

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript run when current-position media data has loadedTry it
onloadeddata="fn()"Call a named function from the attributeTry it
addEventListener("loadeddata")Preferred modern listener on the media elementTry it
With other media eventsUsually after loadedmetadata; before or with canplayTry it

Live Preview

Load a sample clip. When current-frame data is ready, status updates. Use Reload to fire loadeddata again.

Media

Sample media from /video/count.mp4 or /audio/count.mp3.

Player

Waiting for loadeddata…

HTML Examples

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

Example 1 — Inline onloadeddata on Audio

Call a function when current-position media data has loaded.

HTML
<audio controls onloadeddata="handleLoadedData()">
  <source src="/audio/count.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<p id="status">Waiting for loadeddata…</p>

<script>
  function handleLoadedData() {
    document.getElementById("status").textContent =
      "loadeddata fired — current frame data is ready.";
  }
</script>
Try It Yourself

How It Works

  1. Put onloadeddata on the media element — here <audio>, not on <source>.
  2. Browser loads media data for the current playback position (readyState ≥ HAVE_CURRENT_DATA).
  3. loadeddata fires and the attribute runs handleLoadedData().
  4. Update UI — for video, a common use is showing the first frame or hiding a spinner.

Example 2 — addEventListener on Video

Same event with the preferred script pattern, plus a readyState check.

HTML
<video id="clip" width="400" height="225" controls>
  <source src="/video/count.mp4" type="video/mp4">
  Your browser does not support the video element.
</video>
<p id="log">Loading media…</p>

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

  function markReady() {
    log.textContent =
      "loadeddata — readyState " + clip.readyState + " (HAVE_CURRENT_DATA+).";
  }

  clip.addEventListener("loadeddata", markReady);
  if (clip.readyState >= 2) markReady();
</script>
Try It Yourself

How It Works

  1. Select the video with getElementById.
  2. Register loadeddata with addEventListener.
  3. Check readyState >= 2 in case data was already available before the listener attached.
  4. Show status when the current frame’s data is ready (often the first painted frame).

Example 3 — Where loadeddata Fits in the Load Order

Log related media events so you can see the usual sequence.

HTML
<audio id="audio" controls>
  <source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<ul id="log"></ul>

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

  function add(line) {
    var li = document.createElement("li");
    li.textContent = line;
    log.appendChild(li);
  }

  audio.addEventListener("loadedmetadata", function () {
    add("loadedmetadata — duration known");
  });
  audio.addEventListener("loadeddata", function () {
    add("loadeddata — current frame data ready");
  });
  audio.addEventListener("canplay", function () {
    add("canplay — enough buffered to start");
  });
</script>
Try It Yourself

How It Works

  1. loadedmetadata — duration and basic media info are known.
  2. loadeddata — data for the current playback position is available.
  3. canplay — enough ahead that playback can start.
  4. Order can vary slightly by browser and network, but this sequence is the usual teaching model.

Edge Cases & Pitfalls

Most surprises come from treating “frame ready” as “can play through,” or missing the event on data-saver mobiles.

mobile

Data-saver can suppress loadeddata

Per MDN, some mobile browsers with data-saver on may never fire loadeddata. Pair with other signals or UI fallbacks.

meaning

Not the same as canplay

Current-frame data ≠ enough buffered to start smoothly. Use oncanplay / oncanplaythrough for playback readiness.

target

Listen on audio/video, not source

The event targets the media element. Nested <source> tags do not receive onloadeddata.

preload

Depends on buffering policy

With preload="none", little data may load until play — so loadeddata can be delayed.

timing

May already be past readyState 2

If you attach a listener late, check media.readyState >= 2 and run your handler immediately when needed.

Browser Support

onloadeddata 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

onloadeddata

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support loadeddata on audio and video. Mobile data-saver modes may skip the event.

97% 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 9+
Supported
onloadeddata Widely supported

Bottom line: Safe to use for media load UI. Prefer addEventListener('loadeddata') in apps; account for mobile data-saver gaps.

Key Takeaways

  • Role: current playback position’s media data finished loading (often first frame).
  • readyState: typically HAVE_CURRENT_DATA (2) or greater.
  • Order: after loadedmetadata; before/near canplay.
  • Mobile: data-saver may prevent the event — plan a fallback.

One line: onloadeddata means the current frame’s data is ready — not that the whole file can play through.

Frequently Asked Questions

It is an event-handler attribute on audio or video. When the frame at the current playback position finishes loading (often the first frame), the loadeddata event fires and the JavaScript in onloadeddata runs. That corresponds to readyState HAVE_CURRENT_DATA or greater.
The HTML audio and video elements. Put the handler on the media element itself, not on nested source tags.
loadedmetadata means duration and dimensions (or track info) are known. loadeddata means media data for the current playback position has loaded — often the first frame you can display.
loadeddata means current-frame data is available (HAVE_CURRENT_DATA). canplay means enough is buffered that playback can start (HAVE_FUTURE_DATA). canplay typically comes at or after loadeddata.
MDN notes that loadeddata may not fire on mobile or tablet devices when a data-saver setting is on in the browser.
No. The loadeddata event and onloadeddata handler are standard HTML media features and Baseline widely available since about July 2015.

Next: onloadedmetadata

Learn when media duration and size become available.

onloadedmetadata 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