<audio> : Audio element

Introduction

The ‘<audio>‘ element in HTML is used to embed audio content, such as music or sound effects, directly into a web page. It allows you to include audio files that can be played by the user’s browser without the need for external plugins. The ‘<audio>‘ element supports various audio formats, and you can provide multiple sources to ensure compatibility with different browsers.

Here is a basic example of how the ‘<audio>‘ element is typically used :

Output :

In this example:

  • The controls attribute adds audio playback controls, such as play, pause, and volume.
  • The ‘<source>‘ element inside ‘<audio>‘ specifies the audio file (audio-file.mp3) and its type (audio/mp3). You can provide multiple ‘<source>‘ elements with different file formats to ensure compatibility across browsers.

Additional attributes you can use with the <audio> element include:

  • autoplay: Automatically starts playing the audio when the page loads.
  • loop: Causes the audio to loop continuously.
  • preload: Specifies whether the audio should be preloaded. Values can be “auto,” “metadata,” or “none.”

In this way we use ‘<audio>‘ tag.

Leave a Comment