HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: source

The HTML Tag: source is used to specify the source of media files such as images, videos, audio, and other multimedia content. It is an essential tag in HTML that helps to load media files on web pages. The source tag is used in conjunction with other tags such as the video tag, audio tag, and picture tag to specify the source of the media file.

The HTML Tag: source is used to specify the source of media files. It is an empty tag that does not require a closing tag. The source tag is used in conjunction with other tags such as the video tag, audio tag, and picture tag to specify the source of the media file. The source tag has several attributes that are used to specify the source of the media file. The most common attributes used with the source tag are the src attribute and the type attribute.

The src attribute is used to specify the URL of the media file. The URL can be a relative or absolute URL. The type attribute is used to specify the MIME type of the media file. The MIME type is a standard way of identifying the type of media file. For example, the MIME type for an image file is image/jpeg, and the MIME type for a video file is video/mp4.

Example 1: Image Tag with Source Tag

The following code example shows how to use the source tag with the image tag to specify the source of an image file:


<img src="image.jpg" alt="Image">

The above code example specifies the source of the image file as "image.jpg". The alt attribute is used to specify the alternative text for the image.

Example 2: Video Tag with Source Tag

The following code example shows how to use the source tag with the video tag to specify the source of a video file:


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

The above code example specifies the source of the video file as "video.mp4" and "video.ogg". The type attribute is used to specify the MIME type of the video file. The controls attribute is used to display the video controls such as play, pause, and volume. The video tag also includes a fallback message for browsers that do not support the video tag.

Example 3: Audio Tag with Source Tag

The following code example shows how to use the source tag with the audio tag to specify the source of an audio file:


<audio controls>
  <source src="audio.mp3" type="audio/mpeg">
  <source src="audio.ogg" type="audio/ogg">
  Your browser does not support the audio tag.
</audio>

The above code example specifies the source of the audio file as "audio.mp3" and "audio.ogg". The type attribute is used to specify the MIME type of the audio file. The controls attribute is used to display the audio controls such as play, pause, and volume. The audio tag also includes a fallback message for browsers that do not support the audio tag.

Activity