Problem Statement
Which HTML5 tag is used to embed audio content?
Explanation
The audio tag is an HTML5 element used to embed audio content like music, podcasts, or sound effects in web pages. Before HTML5, you needed plugins like Flash to play audio. The audio tag makes it much simpler. The audio tag has several useful attributes. The controls attribute adds play, pause, and volume controls. The autoplay attribute starts playing automatically, though this is often blocked by browsers for better user experience. The loop attribute repeats the audio continuously. The muted attribute starts with sound off. Inside the audio tag, you use source tags to specify audio files. You can provide multiple source tags with different audio formats for browser compatibility. Common formats include MP3, which is widely supported, OGG for Firefox, and WAV for high quality. The browser will use the first format it supports. You should also include fallback text inside the audio tag for browsers that do not support the audio element.
Code Solution
SolutionRead Only
<!-- Basic audio with controls --> <audio controls> <source src="song.mp3" type="audio/mpeg"> <source src="song.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio> <!-- Auto-play and loop --> <audio autoplay loop muted> <source src="background.mp3" type="audio/mpeg"> </audio> <!-- Multiple format support --> <audio controls> <source src="podcast.mp3" type="audio/mpeg"> <source src="podcast.ogg" type="audio/ogg"> <source src="podcast.wav" type="audio/wav"> Audio not supported </audio>
