HTML Audio

HTML audio tag is used to insert an audio message inside the HTML document.

General Syntax

      
        <audio src="" controls="controls"></audio>      
    
Try it now

Source Code

          
            <audio src="assets/html/piano.mp3" controls="controls">
  Your browser does not support audio element.
</audio>          
        
Try it now

Source Code : Output

Multiple Audio

You can also place multiple audio formats of the same file. The browser will select the first one that will be able to play.

General Syntax

      
        <audio controls>
  <source src="" type="audio/ogg" />
  <source src="" type="audio/mpeg" />
</audio>      
    
Try it now

Source Code

          
            <audio controls>
  <source src="piano.ogg" type="audio/ogg" />
  <source src="piano.mp3" type="audio/mpeg" />
  Your browser doesn't support audio element.
</audio>          
        
Try it now

Source Code : Output

Audio Attributes

Followings are the audio attributes:

  • src - It is used to provide an audio file path.
  • controls - It is used to create a control for play/pause, volume, etc.
  • autoplay - It is used to play audio files automatically when the page is loaded.
  • loop - It specifies that the audio will play again after the end.

General Syntax

      
        <audio controls autoplay loop></audio>      
    
Try it now

Source Code

          
            <audio controls autoplay loop>
  <source src="assets/html/piano.ogg" type="audio/ogg" />
  <source src="assets/html/piano.mp3" type="audio/mpeg" />
  Your browser doesn't support audio element.
</audio>          
        
Try it now

Source Code : Output

Web Tutorials

HTML Audio
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4