05 / 12

What is the <source> tag used for?

Understanding the <source> Tag

The <source> tag in HTML is used inside <audio> and <video> elements to specify multiple media files. This helps provide different formats so that the browser can choose the one it supports.

Key Points about <source>
  1. 1

    It is always used inside <audio> or <video> elements.

  2. 2

    Allows you to provide multiple file formats (e.g., MP4, WebM, Ogg for videos; MP3, OGG, WAV for audio).

  3. 3

    Browsers will pick the first format they support and ignore the rest.

  4. 4

    It uses the src attribute to specify the file and the type attribute to indicate the media type (like video/mp4 or audio/mpeg).

Example Usage

In short: The <source> tag is used to provide different versions of the same media file, ensuring better browser compatibility.