The audio Tag
The <audio>
tag allows you to play audio files like mp3, wav, etc., on a webpage.
Using the audio Tag
<audio controls>
<source src="your-audio.mp3" type="audio/mp3" />
Your browser does not support the audio element.
</audio>
Key Attributes
-
controls
: Displays the controls for play, pause, volume, etc. -
<source>
: Specifies the path and type of the audio file
Considerations When Using <audio>
Tag
-
Alternative Text
: The text written between the audio tags defines what will be shown in browsers that do not support the audio element. -
File Size
: Large audio files can affect the loading time of webpages. Therefore, it is recommended to use smaller audio files when possible.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.