HTML Audio

How to insert Audio in HTML?

HTML audio element is used to play an audio file on a web page.

Linking to a sound file using a href allows a browser to open and play an audio file if the viewer of your web page has properly configured their Internet browser.


Example to insert audio in HTML

                          
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>HTML Audio Example</title>
</head>
<body>

  <h2>Audio Example</h2>

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

</body>
</html>
                          
                        

The <audio> element is used to embed an audio player.

The controls attribute adds playback controls (play, pause, volume, etc.) to the audio player.

The <source> element is used to specify the audio file's source (src) and type (type). Multiple <source> elements can be used to provide alternative audio formats for better browser compatibility.