-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics
<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.
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics