How to Add Audio in HTML
Use the <audio> element when you want visitors to play sound directly on your page. This works well for podcasts, lesson narration, product sounds, music previews, and interview clips.
What you’ll build or solve
You’ll learn how to add audio in HTML using the <audio> tag and a <source> file. You’ll also know how to show playback controls so users can play, pause, and adjust volume.
Learn HTML on Mimo
When this approach works best
This approach is the right choice when the audio file is part of the page experience and users should not need to leave the site.
Common real-world scenarios include:
- Podcast episodes
- Language lesson pronunciation clips
- Guided meditation audio
- Product sound demos
- Interview snippets
This is a bad idea when you only want to link to an external audio platform. In that case, a normal <a> link may be enough.
Prerequisites
You only need:
- A basic HTML file
- An audio file, such as
.mp3 - A text editor
- Basic HTML knowledge
Step-by-step instructions
Step 1: Add the <audio> tag with a <source> file
Use the <audio> element and place a <source> tag inside it.
HTML
<audio controls>
<source src="lesson-audio.mp3" type="audio/mpeg">
</audio>
To add fallback text for unsupported browsers, place it inside the <audio> tag below the source.
HTML
<audio controls>
<source src="podcast-episode.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
What to look for:
controlsshows play, pause, timeline, and volume controls<source>points to the audio filetype="audio/mpeg"is common for.mp3- Add fallback text for unsupported browsers
- Keep the file path accurate, especially if the file is inside another folder
Examples you can copy
Podcast clip
HTML
<audio controls>
<source src="podcast-preview.mp3" type="audio/mpeg">
</audio>
Pronunciation lesson
HTML
<audio controls>
<source src="english-pronunciation.mp3" type="audio/mpeg">
</audio>
Product sound demo
HTML
<audio controls>
<source src="notification-sound.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Common mistakes and how to fix them
Mistake 1: Forgetting the controls attribute
What the reader might do:
HTML
<audio>
<source src="lesson-audio.mp3" type="audio/mpeg">
</audio>
Why it breaks: the audio may load, but users do not get visible playback controls.
Corrected approach:
HTML
<audio controls>
<source src="lesson-audio.mp3" type="audio/mpeg">
</audio>
Mistake 2: Using the wrong file path
What the reader might do:
HTML
<audio controls>
<source src="audio/demo.mp3" type="audio/mpeg">
</audio>
Why it breaks: if the file is not in that folder, the browser cannot load it.
Corrected approach:
HTML
<audio controls>
<source src="demo.mp3" type="audio/mpeg">
</audio>
Use the real file location relative to your HTML file.
Mistake 3: Leaving out the file type
What the reader might do:
HTML
<audio controls>
<source src="lesson-audio.mp3">
</audio>
Why it breaks: some browsers rely on the type value to recognize the audio format more reliably.
Corrected approach:
HTML
<audio controls>
<source src="lesson-audio.mp3" type="audio/mpeg">
</audio>
Troubleshooting
If the audio does not appear, check the src file path.
If the audio appears but does not play, confirm the file format is supported, such as .mp3.
If users cannot control playback, add the controls attribute.
If the wrong file plays, verify the source file name and folder location.
Quick recap
- Use
<audio>to add sound to the page - Add a
<source>tag inside it - Use
controlsfor playback controls - Set the correct file path and file type
- Add fallback text for unsupported browsers
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot