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:
src – media file path (used in <audio> and <video> elements)[cite: 3].srcset – image file path or variants list (used in <picture>)[cite: 3].type – specifies MIME type (e.g., video/mp4, audio/mpeg, image/webp) helping browsers decide playability[cite: 3].media – media query e.g., (min-width: 800px), defining usage conditions[cite: 3].class, id, and style are also used[cite: 3].In the example below, the <source> tag provides two audio formats so the browser plays the first supported one[cite: 3]:
Code:
The browser will interpret this code as follows: