<source> Tag in HTML | Media Element

The <source> tag in HTML is used to specify multiple media resources for the <audio> and <video> elements. It allows browsers to choose the appropriate file based on the media type and supported formats.

Key Points on <source> Tag:

Syntax of <source> Tag:

Syntax Example

<source src="mediafile.mp4" type="video/mp4">

Example of <source> Tag in HTML:

This example demonstrates how the <source> tag is used to specify multiple video formats for the <video> element.

Code Example

<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>HTML Source Tag Example</title>
        </head>
        <body>
            <h1>HTML Source Tag Example</h1>
            <video controls>
                <source src="video.mp4" type="video/mp4">
                <source src="video.ogg" type="video/ogg">
                <p>Your browser does not support the video tag.</p>
            </video>
        </body>
        </html>

Output

The <source> tag is essential when embedding media content like videos or audio in HTML. It ensures that the browser can pick the right format based on the user's environment and preferences, improving compatibility and performance.