<source>

HTML4 HTML5

The <source> tag is an empty element (lacking a closing tag) defining alternative media resources for <audio>, <video>, and <picture> elements[cite: 3].

It allows the browser to select the most appropriate file based on supported media formats or display conditions (such as screen resolution or pixel density for images)[cite: 3].

Attributes:

Example

In the example below, the <source> tag provides two audio formats so the browser plays the first supported one[cite: 3]:

Code:

<audio controls> <source src="audio-sample.mp3" type="audio/mpeg"> <source src="audio-sample.ogg" type="audio/ogg"> Your browser does not support the audio player. </audio>

The browser will interpret this code as follows: