What is the <audio> tag in HTML?
The <audio> tag is used to embed audio files in a web page. It allows users to play sound content like music, podcasts, or voice recordings directly in the browser.
Basic Syntax of <audio>:
<audio controls>
<source src="audiofile.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Common Attributes of <audio>:
-
src
-
controls
-
Adds play, pause, and volume controls for the user.
-
Example: <audio controls>
-
autoplay
-
The audio starts playing automatically when the page loads.
-
Note: Often blocked by browsers until user interaction.
-
Example: <audio autoplay>
-
loop
-
muted
-
preload