HTML Media

HTML provides several elements and attributes to embed and control various types of media content within a web page. These elements allow you to include images, audio, video, and other multimedia elements in your HTML documents.


Here are some of the main HTML elements used for media:


1. `<img>`: The `<img>` element is used to display images on a web page. You specify the image source using the `src` attribute, like this:

html
<img src="image.jpg" alt="Description of the image">

The `alt` attribute provides alternative text for the image, which is displayed if the image cannot be loaded.


2. `<audio>`: The `<audio>` element is used to embed audio content in a web page. You can specify multiple audio sources using the `<source>` element nested inside the `<audio>` element. This allows the browser to choose the supported format. Here's an example:

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

The `controls` attribute adds a default set of audio playback controls to the audio player.


3. `<video>`: The `<video>` element is used to embed video content in a web page. Similar to the `<audio>` element, you can specify multiple video sources using the `<source>` element. Here's an example:

html
<video controls width="400">
    <source src="video.mp4" type="video/mp4">
    <source src="video.webm" type="video/webm">
    Your browser does not support the video element.
</video>

The `controls` attribute adds default video controls, and the `width` attribute sets the width of the video player.


4. `<iframe>`: The `<iframe>` element allows you to embed external web content within your HTML document. It can be used to embed videos from platforms like YouTube or Vimeo or display web pages from other domains. Here's an example:

html
<iframe src="https://www.youtube.com/embed/VIDEO_ID"></iframe>

The `src` attribute specifies the URL of the content you want to embed.


These are just a few examples of HTML media elements. HTML also provides attributes and APIs to control playback, customize appearance, and handle media events. You can refer to the HTML specification and various documentation resources for more detailed information on working with media in HTML.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext