Category: react
HTML audio and video
Published on 23 Jun 2026
Explanation
HTML provides the <audio> and <video>
elements to embed media directly into
web pages without requiring external plugins.
Code:
<audio controls> <source src="song.mp3" type="audio/mpeg"> </audio>
Explanation
The <audio> element is used to
play audio files. The controls attribute
displays play, pause, and volume controls.
Code:
<audio controls> <source src="music.mp3" type="audio/mpeg"> Your browser does not support audio. </audio>
Explanation
The <video> element is used to
display video content. The controls
attribute
allows users to play, pause, and
seek through the video.
Code:
<video width="400" controls> <source src="video.mp4" type="video/mp4"> </video>
Explanation
Multiple source elements can be provided
to support different media formats and
improve browser compatibility.
Code:
<video controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.webm" type="video/webm"> </video>
Explanation
Additional attributes such as autoplay,
muted,
loop, and poster can enhance the
user experience when working with audio
and video elements.
Code:
<video controls autoplay muted loop poster="thumbnail.jpg"> <source src="demo.mp4" type="video/mp4"> </video>