HTML - <audio> tag in HTML
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
-
Specifies the path to the audio file.
-
Example: <audio src="song.mp3">
-
-
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
-
Repeats the audio after it finishes playing.
-
Example: <audio loop>
-
-
muted
-
Starts the audio in a muted state.
-
Example: <audio muted>
-
-
preload
-
Specifies if and how the audio should be loaded when the page loads.
-
Values:
-
auto: Load the entire file.
-
metadata: Load only metadata (like duration).
-
none: Do not preload.
-
-
Example: <audio preload="metadata">
-