HTML onloadstart Attribute

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

Definition and Usage

The onloadstart attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the loadstart event fires — the browser has started to load the media resource.

It does not mean loading finished. Next steps are often onprogress, onloadedmetadata, then onloadeddata. A common beginner use is showing a “Loading…” status or spinner.

Baseline · Widely available.

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

HTML Syntax

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

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

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript run when the browser starts loading mediaTry it
onloadstart="fn()"Call a named function from the attributeTry it
addEventListener("loadstart")Preferred modern listener on the media elementTry it
With other media eventsUsually first — before progress / loadedmetadataTry it

Live Preview

Reload a sample clip. Status updates when loadstart fires (loading has begun).

Media

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

Player

Waiting for loadstart…

HTML Examples

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

Example 1 — Show “Loading…” on Audio

Update status as soon as the browser starts fetching the file.

HTML
<audio controls onloadstart="showLoading()">
  <source src="/audio/count.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<p id="status">Idle</p>

<script>
  function showLoading() {
    document.getElementById("status").textContent =
      "loadstart — browser started loading media.";
  }
</script>
Try It Yourself

How It Works

  1. Put onloadstart on the media element — not on <source>.
  2. Browser begins a fetch for the media resource (subject to preload).
  3. loadstart fires and your script updates the status text.
  4. Loading continues — metadata and frames arrive in later events.

Example 2 — addEventListener on Video

Same event with the preferred script pattern; count how often loading starts.

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">Waiting…</p>

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

  clip.addEventListener("loadstart", function () {
    count += 1;
    log.textContent = "loadstart fired (" + count + ") — loading began.";
  });
</script>
Try It Yourself

How It Works

  1. Select the video with getElementById.
  2. Register loadstart with addEventListener.
  3. When a load begins, increment a counter and update the log.
  4. Changing src or calling load() can fire loadstart again.

Example 3 — Where loadstart 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("loadstart", function () {
    add("loadstart — looking for media");
  });
  audio.addEventListener("progress", function () {
    add("progress — downloading…");
  });
  audio.addEventListener("loadedmetadata", function () {
    add("loadedmetadata — duration known");
  });
</script>
Try It Yourself

How It Works

  1. loadstart — the browser begins looking for / fetching media.
  2. progress — download is underway (may fire many times).
  3. loadedmetadata — duration and dimensions/tracks are known.
  4. Later: loadeddata and canplay as more data arrives.

Edge Cases & Pitfalls

Most surprises come from expecting “finished” when the event only means “started.”

meaning

Start ≠ ready to play

loadstart only means a load began. Use oncanplay (or later events) before treating media as playable.

preload

preload="none" can delay loadstart

With preload="none", the browser may wait until play before fetching — so loadstart is delayed.

repeat

May fire more than once

Changing the resource, calling load(), or a new network attempt can fire loadstart again. Keep handlers idempotent.

target

Listen on audio/video, not source

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

errors

Failed loads still started

loadstart can fire before a failure. Pair with onerror / onabort for error UI.

Browser Support

onloadstart 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

onloadstart

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support loadstart on audio and video.

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
onloadstart Widely supported

Bottom line: Safe to use for “loading began” UI. Prefer addEventListener('loadstart') in apps.

Key Takeaways

  • Role: browser started loading the media resource.
  • Not finished: duration and frames come in later events.
  • Order: often first — then progress, loadedmetadata, …
  • UI tip: great place to show a loading status; hide it on later ready events.

One line: onloadstart means “fetch began” — pair it with later media events for “ready.”

Frequently Asked Questions

It is an event-handler attribute on audio or video. When the browser starts loading the media resource, the loadstart event fires and the JavaScript in onloadstart runs.
The HTML audio and video elements. Put the handler on the media element itself, not on nested source tags.
No. It only means loading has begun. Duration comes later with loadedmetadata; current-frame data with loadeddata; progress reports ongoing download.
It is typically one of the first events in the media load sequence — before progress, loadedmetadata, loadeddata, and canplay.
Often not until the user presses play (or you call load()/play()), because the browser may delay fetching. Timing depends on preload and the browser.
No. The loadstart event and onloadstart handler are standard HTML media features and Baseline widely available since about July 2015.

Next: onmousedown

Handle the moment a mouse button is pressed on an element.

onmousedown 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