At the end of this tutorial, you’ll be able to:
Basic Example:
<video width="400" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Common Attributes
Styling Video with CSS
You can style the video so that it would match your page,
for example:
<style>
video {
border: 3px solid #444;
border-radius: 10px;
width: 100%;
max-width: 500px;
}
</style>
<video controls poster="poster.jpg">
<source src="sample.mp4" type="video/mp4">
</video>
Quick Recap
The <audio> tag is used to embed sound files, such as music or podcasts.
Basic Example:
<audio controls>
<source src="sound.mp3" type="audio/mpeg">
<source src="sound.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
Common Attributes
Styling Audio with CSS
Although browsers provide default controls, you can style the container/background.
<style>
audio {
width: 300px;
background-color: #f5f5f5;
border-radius: 8px;
}
</style>
Quick Overview
The <audio> tag is a great way to integrate sound or music into a website.
For maximum compatibility, always use formats such as MP3 and OGG.
<video width="400" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
</video>
<style>
video {
border: 3px solid #444;
border-radius: 10px;
width: 100%;
max-width: 500px;
}
</style>
<video controls poster="poster.jpg">
<source src="sample.mp4" type="video/mp4">
<source src="sample.ogg" type="video/ogg">
</video>
Different web browsers support different technical data formats. It is good to include an MP4 version, and an OGG version if you wish to be as compatible as possible.
Yes, you can add subtitles using the <track> tag inside the <video> tag.
Autoplay should only be used if the video is muted—the majority of web browsers do not support autoplay if sound is included.
Use CSS to set the video width to a percentage (e.g., width: 100%) and set a max-width if needed. This ensures the video scales properly across desktops, tablets, and mobile screens.
HTML <audio> only plays one track at a time. To offer multiple tracks, you can use JavaScript to switch sources dynamically or provide multiple <audio> elements for users to choose from.
3rd Floor, Aval Complex, University Road, above Balaji Super Market, Panchayat Nagar Chowk, Indira Circle, Rajkot, Gujarat 360005.
Abbotsford, BC
15th B Street 103, al Otaiba Dubai DU 00000, United Arab Emirates
3rd Floor, Aval Complex, University Road, above Balaji Super Market, Panchayat Nagar Chowk, Indira Circle, Rajkot, Gujarat 360005.
Abbotsford, BC
15th B Street 103, al Otaiba Dubai DU 00000, United Arab Emirates
Copyright © 2026 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.