HTML Multimedia

In modern HTML, multimedia content like audio and video can be embedded directly into the web page. There are several ways to embed multimedia content in an HTML page.

Embedding Video in HTML

To embed a video in HTML, we can use the <video> tag. Here is a sample code that embeds a video in an HTML page:

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

The <video> tag is used to define a video player on a web page. The width and height attributes are used to set the dimensions of the video player. The "controls" attribute adds standard video controls such as play, pause, and volume.

The <source> tag is used to specify the video file to be played. The "src" attribute is used to specify the location of the video file. The "type" attribute is used to specify the MIME type of the video file. In the example above, the video file "video.mp4" is played if the browser supports the MP4 video format. If the browser does not support the video format, the text "Your browser does not support the video tag." is displayed.

Embedding Audio in HTML

To embed audio in HTML, we can use the <audio> tag. Here is a sample code that embeds an audio file in an HTML page:

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

The <audio> tag is used to define an audio player on a web page. The "controls" attribute adds standard audio controls such as play, pause, and volume.

The <source> tag is used to specify the audio file to be played. The "src" attribute is used to specify the location of the audio file. The "type" attribute is used to specify the MIME type of the audio file. In the example above, the audio file "audio.mp3" is played if the browser supports the MP3 audio format. If the browser does not support the audio format, the text "Your browser does not support the audio element." is displayed.

Embedding YouTube Videos

To embed a YouTube video in HTML, we can use the <iframe> tag. Here is a sample code that embeds a YouTube video in an HTML page:

<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>
run this source code Browser View

The <iframe> tag is used to embed a webpage within a webpage. The "src" attribute is used to specify the URL of the YouTube video to be embedded. The "width" and "height" attributes are used to set the dimensions of the video player. The "allowfullscreen" attribute allows the video to be played in fullscreen mode.

Full Source Code | HTML
<!DOCTYPE html> <html> <head> <title>Embedding Multimedia Content</title> </head> <body> <h1>My Video</h1> <video width="640" height="360" controls> <source src="myvideo.mp4" type="video/mp4"> <source src="myvideo.webm" type="video/webm"> Your browser does not support the video tag. </video> <h1>My Audio</h1> <audio controls> <source src="myaudio.mp3" type="audio/mpeg"> <source src="myaudio.ogg" type="audio/ogg"> Your browser does not support the audio tag. </audio> </body> </html>
run this source code Browser View

My Video

My Audio

In the above example, included a video and an audio file using the video and audio tags, respectively. The source tag is used to specify the location of the multimedia file and its file type. In case the browser doesn't support the specified file type, a fallback message is displayed using the text between the opening and closing tags.

The controls attribute in both the video and audio tags is used to display a set of playback controls such as play/pause, volume, and full-screen mode.

Note that the video and audio tags can also accept other attributes to control their behavior and appearance, such as autoplay, loop, and poster for videos, and preload, muted, and controlsList for audios.

Conclusion:

Embedding multimedia content in an HTML page is easy using the appropriate HTML tags and attributes. By using the source tag to provide different file types, you can ensure that our multimedia content can be viewed by a wider range of browsers.