HTML Embedding Audio


The <audio> tag allows you to embed sound files (such as music, narration, or sound effects) into your web page with optional controls like play, pause, and volume.

Syntax

<audio src="sound.mp3" controls></audio> 

html-audio


Example

 <audio controls>
  <source src="audio.mp3" type="audio/mpeg">
  <source src="audio.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

Attributes of <audio>

Attribute Description
src Path or URL to the audio file
controls Displays default player controls (play, pause, volume)
autoplay Automatically starts playing the audio when page loads
loop Plays the audio file in a continuous loop
muted Starts playback with audio muted
preload Hints how the browser should load the audio (auto, metadata, none)

Example: Autoplay + Loop + Muted

<audio src="background.mp3" autoplay loop muted></audio> 

notepad
  • Offer multiple audio formats for browser compatibility
  • Always include a fallback message for older browsers
  • Never autoplay unless necessary (and always muted if so)
  • Include alt text or caption elsewhere if audio is critical



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.