HTML的source标签


HTML Source Tag

HTML source tag () is used to specify alternative media resources like video, audio, and image files that contain the same content but are different in terms of format, quality, or size.

Syntax

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

Attributes

  • src - Defines the URL of media file
  • type - Defines the media type

Usage Example

<video controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

This example shows that if the browser does not support the first media format, it will attempt to play the second format specified.

Compatibility

The tag is supported in all modern browsers and versions of Internet Explorer from version 9 onwards.

Conclusion

HTML source tag is an essential tool for web developers who want to provide alternative media resources for multimedia content. By using the tag, web developers can ensure that their website audio and video content is widely accessible to all users.