HTML5 provides robust support for multimedia elements, allowing you to easily embed audio and video content directly into your web pages without relying on external plugins.
The audio element is used to embed sound content in documents. It can contain one or more audio sources, represented using the source element. The browser will choose the first source it supports.
Attribute | Description | Example |
---|---|---|
src | Specifies the URL of the audio file. |
Try yourself
|
controls | Specifies that audio controls should be displayed (such as a play/pause button). |
Try yourself
|
autoplay | Specifies that the audio will start playing as soon as it is ready. |
Try yourself
|
loop | Specifies that the audio will start over again, every time it is finished. |
Try yourself
|
The video element is used to embed video content in documents. It can contain one or more video sources, represented using the <source> element. The browser will choose the first source it supports.
Attribute | Description | Example |
---|---|---|
src | Specifies the URL of the video file. |
Try yourself
|
controls | Specifies that video controls should be displayed (such as a play/pause button). |
Try yourself
|
autoplay | Specifies that the video will start playing as soon as it is ready. |
Try yourself
|
loop | Specifies that the video will start over again, every time it is finished. |
Try yourself
|
poster | Specifies an image to be shown while the video is downloading, or until the user hits the play button. |
Try yourself
|
Here is how you can use audio and video elements in your HTML:
Example: Audio Element
<audio controls>
<source src="/media/audio/sample.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
This example shows an audio element with controls to play, pause, and adjust the volume.
<video controls>
<source src="/media/video/sample_video_720x480_2mb.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
This example shows a video element with controls to play, pause, and adjust the volume.
Here are some important notes and best practices when using HTML multimedia elements: