How to define the type of media resource in HTML5?

The correct identification of media resources in HTML5 is an utmost imperative for web designers and developers, as it empowers them to fabricate a lavish multimedia encounter for their spectators. With the emergence of HTML5, the procedure of defining and presenting media resources on a webpage has undergone a significant metamorphosis. In this article, we shall scrutinize the complexities of specifying the media resource type in HTML5, furnishing web artisans with the expertise and utilities to enrich the accessibility and efficiency of multimedia content on their web pages.

<source> Tag

The "source" tag within HTML serves the purpose of designating the source directory or site of media elements, such as images, audio, and video, intended for manifestation on a web page. Usually, the "source" tag is employed within the "video" and "audio" tags, to provide a wide range of media files with varying formats or resolutions.


<source src="file_location" type="media_type">

The "source" tag is an empty tag, which means it does not have a closing tag. It has two required attributes −

  • "src" − This attribute specifies the URL or file path of the media content to be displayed. It can be a relative or absolute URL.

  • "type" − This attribute specifies the MIME type of the media content. The MIME type tells the browser what kind of media it is and how to handle it. It is important to include this attribute to ensure that the browser can handle the media content properly.


To particularize the classification of multimedia resource utilizing the tag within HTML5, follow the ensuing guidelines −

  • Construct a video component within the HTML text and add the "controls" attribute to allow the user to govern the video playback.

  • Embed one or more tags within the video component, with the "src" attribute denoting the location of the video file and the "type" attribute defining the MIME type of the video.

  • Furnish a supplementary message to manifest in the case of the user's browser being incompetent in supporting the video component.


In the following code, we instantiate a video element that has the "controls" attribute, allowing the viewer to govern the video playback. Afterwards, we include two source tags that identify the video file's location and MIME type. Lastly, we set a fallback message to appear if the browser fails to render the video element. This illustration highlights how to define diverse video file types that can be compatible with a variety of devices and web browsers, resulting in more convenient and adaptable multimedia content on a web page.

<!DOCTYPE html>
      <title>How to define the type of media resource in HTML5?</title>
      <h4>How to define the type of media resource in HTML5?</h4>
      <video controls>
         <source src="" type="video/mp4">
         Your browser does not support the video tag.


In summary, precisely specifying the media resource type in HTML5 can significantly amplify user engagement and retention rates, resulting in an improved browsing experience. By adhering to the techniques and directives discussed in this article, web developers and designers can effortlessly integrate multimedia content into their web pages, irrespective of file format or encoding. Attention to detail and an unwavering dedication to perfection distinguish an adept web artisan, and the ability to efficiently define the media resource type in HTML5 is a crucial element of their arsenal. We trust that this article has furnished valuable insights and knowledge to assist web artisans in crafting fascinating and compelling multimedia content for their audience.

Updated on: 05-May-2023


Kickstart Your Career

Get certified by completing the course

Get Started