Source Tag
The <source>
tag in HTML5 allows web developers to specify multiple media resources for media elements, such as <video>
and <audio>
. This tag ensures that the media attachments will render smoothly, regardless of what platform, device, or browser a user is running, thereby providing a seamless user experience across all platforms.
Its advantage is the possibility to offer a variable set of video or audio formats, resolutions, and bitrates. Moreover, it signals a major shift away from Flash video, which is characterized by incompatibilities and resource-demanding characteristics. In simple terms, the <source>
tag enables browser-native fallbacks, which can provide alternative media sources for the system or device that can’t support the initial file format.
<video controls>
<!-- MP4 for Safari, IE9, iPhone, iPad, Android, and Windows Phone 7 -->
<source type="video/mp4" src="movie.mp4" />
<!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
<source type="video/webm" src="movie.webm" />
<!-- Ogg/Vorbis for older Firefox and Opera versions -->
<source type="video/ogg" src="movie.ogv" />
<!-- Optional: Add subtitles for each language -->
<track kind="subtitles" src="subs_en.vtt" srclang="en" />
<track kind="subtitles" src="subs_de.vtt" srclang="de" />
<!-- Optional: Add in fallback for Flash -->
<object type="application/x-shockwave-flash" data="flash_player.swf">
<!-- Fall back content here -->
</object>
</video>
In this example, the browser will use the first source it supports, defined by the formats mp4, webm, and ogg in that order. You’re not limited to these formats only, you can use any file format that your audience’s browser supports. This is a versatile way to ensure that all visitors, regardless of their device or browser, can access the media on your site.
Like many advancements in HTML5, the <source>
tag is all about enhancing multimedia content and its accessibility on the web, which is crucial for modern web development projects. The <source>
tag ensures a consistent user experience and helps to avoid playback issues which can frustrate users and affect the perceived quality of the website. Developers and designers should firmly consider the usage and importance of the <source>
tag, as it’s evident it has widespread implications, from enhancing the user interface to improving overall user experience and accessibility. This can especially benefit drupal development whereby the <source>
tag can be a crucial tool in controlling how media is displayed and delivered across platforms.