References

Beginner-friendly references for web development, with live, editable examples.

The HTML preload attribute

Attribute All modern browsers Updated
In short

The HTML preload attribute hints how much of a media file to fetch before playback. It works on <audio> and <video>, takes none, metadata or auto, and browsers treat it as a hint that they may override.

Overview

The preload attribute is a loading hint for media elements. On <video> and <audio> it tells the browser whether to fetch nothing, only the metadata, or as much of the file as it likes before the viewer presses play.

Each value describes a different trade-off. none says the viewer probably will not need the file or the server wants to save traffic. metadata allows the duration, dimensions and track list, and maybe the first few frames. auto, or an empty value, lets the browser put the viewer first, up to downloading the whole resource.

Leaving the attribute out does not mean auto. The HTML Standard makes the missing and invalid defaults implementation-defined and suggests metadata, and MDN's compatibility data notes that Chrome has defaulted to metadata since version 64. An empty preload value, on the other hand, maps to auto.

The hint has limits. autoplay can override it, because media that plays has to buffer, and the standard lets browsers ignore the attribute based on user preferences or the connection. You can also change it from script, for example switching a page of videos from none to auto once the viewer starts one.

Syntax

<video src="lecture.mp4" preload="metadata" controls></video>

Values

Value
none | metadata | auto

Example

Live example
<video id="lazy" src="https://codeshack.io/web/example.mp4" preload="none" controls width="150"></video>
<video id="meta" src="https://codeshack.io/web/example.mp4" preload="metadata" controls width="150"></video>
<p id="out">Waiting for metadata...</p>
<script>
  const lazy = document.getElementById('lazy');
  const meta = document.getElementById('meta');
  const report = () => {
    document.getElementById('out').textContent =
      'none: duration ' + lazy.duration + ' | metadata: duration ' + meta.duration.toFixed(1) + ' s';
  };
  meta.addEventListener('loadedmetadata', report);
  if (meta.readyState > 0) report();
</script>

Best practices

  • Use preload="none" on pages with many videos, which the HTML Standard gives as a way to say they should not download unless requested.
  • Choose metadata when you want the duration and dimensions available before playback without fetching the whole file.
  • Pair preload="none" with a poster image, because the browser has no frame to show until playback begins.
  • Set the attribute explicitly instead of trusting the default, since the default differs between browsers.
  • Do not count on preload for guaranteed savings. autoplay can override it, and browsers may ignore it based on user settings.

Frequently asked questions

What is the default value of the preload attribute?
The preload attribute has no fixed default. The HTML Standard leaves it to each browser and suggests metadata, which MDN notes Chrome has used since version 64.
What is the difference between preload metadata and preload auto?
Preload metadata fetches details such as duration, dimensions and track list, plus maybe a few frames. Preload auto lets the browser download as much as it wants, up to the whole file.
Does preload none stop a video from downloading?
Preload none asks the browser not to fetch the media before the viewer presses play. It is only a hint, and browsers may ignore it based on user settings or the connection.
Does autoplay override the preload attribute?
Yes, autoplay can override the preload attribute. Media that plays has to buffer first, and the HTML Standard notes that using both is still not an error.
Is the preload attribute the same as link rel preload?
No, the preload attribute only hints how much of that audio or video to buffer. The preload value of the link element's rel attribute is a separate feature that fetches a resource early with high priority.
Can I change the preload attribute with JavaScript?
Yes, set the element's preload property to none, metadata or auto. The HTML Standard allows the preload attribute to change even while the media is buffering or playing.