Media
HTML Video
The <video>
element is used to embed video content into an HTML webpage. It supports video formats such as MP4, WebM, and Ogg and includes various attributes to control playback, such as autoplay, controls, and a thumbnail image for the video.
<video>
Example Basic
<video width="220" height="140" controls>
<source src="video.mp4" type="video/mp4" />
</video>
Key Attributes
controls
: Adds video playback controls.autoplay
: Starts video automatically.poster
: Sets a thumbnail image before playback begins.
HTML Video with Auto play and Thumbnail
<video width="450" height="250" autoplay poster="thumbnail.png">
<source src="video.mp4"type="video/mp4" />
</video>
HTML Audio
The <audio>
tag is used for embedding sound content on webpages. It supports formats such as MP3
, WAV
, and Ogg
.
Basic <audio>
Example
<audio controls>
<source src="song.mp3" type="audio/mpeg" />
</audio>
Key Attributes
controls
: Provides audio playback controls.autoplay
: Plays audio automatically.muted
: Mutes the audio by default.
HTML Audio with Controls and Autoplay
<audio controls autoplay>
<source src="song.mp3" type="audio/mpeg" />
</audio>
- To make audio play automatically without sound, add the
muted
attribute along withautoplay
.
<audio controls autoplay muted>
<source src="song.mp3" type="audio/mpeg" />
</audio>
Supported Audio Formats in HTML
Different web browsers support varying audio formats, including MP3, WAV, and OGG. The following table shows the compatibility of these formats across major browsers:
Media Types for Audio Files
The table below lists common audio file formats and their corresponding media types in HTML.
Audio File Formats and Media Types
File Format | Media Type |
---|---|
MP3 | audio/mpeg |
OGG | audio/ogg |
WAV | audio/wav |
Audio Methods, Properties, and Events
The HTML DOM provides various methods and properties for the <audio>
element. These methods enable control over playback, volume, and duration of an audio file. Events can be triggered when the audio starts, pauses, or stops playing.
HTML Audio Tags
Below are the key tags used for embedding audio content in HTML:
HTML Audio Elements
Tag | Description |
---|---|
<audio> | Defines an audio element for embedding sound. |
<source> | Specifies different audio files for compatibility with various browsers. |
Conclusion
HTML provides powerful elements like <video>
and <audio>
for embedding multimedia content on webpages. Using the correct formats and attributes ensures compatibility across browsers, while enhancing user experience. Properly implemented, multimedia elements can make websites more engaging and accessible.
Image
Images enhance a webpage's appearance. In HTML, the <img> tag is used, with the src attribute for the URL and alt for accessibility.
Popover
An HTML popover is a small window that appears upon clicking or hovering over an element, offering additional information or actions, often created with JavaScript or CSS.