HTML Tags

HTML <source> Tag

The <source> tag is used to define multiple media resources for the <audio> and <video> elements.
It allows the browser to choose the best supported format automatically, ensuring better playback compatibility across devices.

Syntax

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

Attributes

AttributeDescriptionExample
srcSpecifies the path (URL) of the media file.src="movie.mp4"
typeDefines the MIME type of the file to help browsers identify the format.type="video/mp4"
mediaSpecifies media query conditions (like screen size) for selecting this file.media="(min-width: 800px)"
sizesSpecifies image sizes for responsive designs (used in <picture>).sizes="(max-width: 600px) 480px, 800px"
srcsetSpecifies multiple image sources for different resolutions (used in <picture>).srcset="image-480.jpg 480w, image-800.jpg 800w"

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Source Tag Example</title>
</head>
<body>
  <h2>Example: Using &lt;source&gt; inside &lt;video&gt;</h2>

  <video width="640" height="360" controls>
    <source src="https://assets.mixkit.co/videos/4834/4834-720.mp4" type="video/mp4">
    <source src="https://assets.mixkit.co/videos/4834/4834-720.webm" type="video/webm">
    Your browser does not support the video tag.
  </video>

  <h2>Example: Using &lt;source&gt; inside &lt;audio&gt;</h2>

  <audio controls>
    <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1" type="audio/mpeg">
    <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.ogg" type="audio/ogg">
    Your browser does not support the audio element.
  </audio>

</body>
</html>

Output

Browser Output

When used inside <audio> or <video>, the browser automatically picks the first supported file format and plays it.
Use our Try It Editor to see how browsers select media formats dynamically.

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

The <source> tag is fully supported in all major browsers starting from Internet Explorer 9.
It ensures media elements remain functional even when certain formats aren’t supported.

Notes

  • Always include at least two <source> elements for best compatibility (e.g., MP4 + WebM for videos).
  • Browsers read <source> elements from top to bottom and stop when they find the first supported format.
  • The <source> tag does not display anything by itself — it must be nested inside <video>, <audio>, or <picture>.

Conclusion

The <source> tag improves the flexibility and compatibility of media elements by letting developers provide multiple file formats.
It ensures that users across all browsers and devices can play the same content smoothly without additional plugins.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend