-
Hajipur, Bihar, 844101
<audio>
Tag?The <audio>
tag in HTML is used to embed sound/audio files into a webpage. It provides built-in controls for playing, pausing, and adjusting volume.
<audio controls>
<source src="sound.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<audio>
Attribute | Description |
---|---|
src |
The path to the audio file |
controls |
Displays play, pause, and volume controls |
autoplay |
Starts playing the audio automatically |
loop |
Repeats the audio when finished |
muted |
Plays the audio with sound muted |
preload |
Hints whether audio should be preloaded |
Format | Type | Browser Support |
---|---|---|
.mp3 |
audio/mpeg |
✅ Widely supported |
.ogg |
audio/ogg |
✅ Firefox, Chrome, Opera |
.wav |
audio/wav |
✅ All modern browsers |
<audio controls autoplay loop muted preload="auto">
<source src="music.mp3" type="audio/mpeg">
<source src="music.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
src
Attribute<audio src="song.mp3" controls></audio>
Audio players are styled by the browser and can’t be fully customized with CSS, but you can style surrounding elements:
<style>
.audio-container {
background: #f9f9f9;
padding: 15px;
border-radius: 8px;
width: 300px;
}
</style>
<div class="audio-container">
<audio controls>
<source src="track.mp3" type="audio/mpeg">
</audio>
</div>
Q1. Embed an .mp3
file using the <audio>
tag.
Q2. Add controls to let users play and pause audio.
Q3. Make the audio autoplay and loop continuously.
Q4. Include a fallback message for unsupported browsers.
Q5. Provide both .mp3
and .ogg
versions of the same file.
Q6. Mute the audio on page load.
Q7. Use preload="none"
and explain the behavior.
Q8. Embed three different audio tracks in one HTML page.
Q9. Style a custom background behind the audio player.
Q10. Add a download link for the same audio file below the player.
Q1: Which HTML tag is used to play audio?
Q2: What does the controls attribute do in <audio>?
Q3: Which attribute repeats the audio when finished?
Q4: What is the most widely supported audio format?
Q5: How do you specify the audio source file?
Q6: What happens if a browser does not support the <audio> tag?
Q7: Which of the following is a valid MIME type for an audio file?
Q8: What does muted do in the <audio> tag?
Q9: What does preload="none" mean?
Q10: Can you include multiple audio formats in one audio tag?