Performance: Audio tag basics
This affects page load speed and interaction responsiveness by how audio files are loaded and played.
<audio src="large-audio-file.mp3" controls preload="none"></audio>
<audio src="large-audio-file.mp3" autoplay></audio>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| <audio autoplay> | Minimal | 0 | Blocks paint until audio starts | [X] Bad |
| <audio controls preload="none"> | Minimal | 0 | Non-blocking paint, loads on user action | [OK] Good |
<audio> tag in HTML?<audio> tag is designed to embed sound files in web pages.<img> for images or <video> for videos, <audio> specifically handles audio content.<audio> tag to show playback controls like play and pause buttons?controls attribute tells the browser to display play, pause, and volume buttons.src sets the audio file, autoplay starts playing automatically, and loop repeats the audio.<audio controls> <source src="sound.mp3" type="audio/mpeg"> <source src="sound.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio>
<source> tags provide alternative audio formats so browsers can pick the one they support.controls attribute shows the player, and fallback text shows only if audio is unsupported.<audio src="music.mp3" controls> <source src="music.ogg" type="audio/ogg"> </audio>
<source> tags inside <audio>, do not use the src attribute on <audio> itself.<source> tags or only src should be used.autoplay attribute starts playing automatically, and loop repeats the audio continuously.controls attribute.Pass the test and this pattern moves unknown