html
  1. html-audio

HTML Audio Tag

The HTML <audio> tag is used to embed audio resources in HTML.

It allows you to play audio on your web page without the need for a third-party plugin.

How to Use the Audio Tag in HTML

Here is an example of how to create an audio element in HTML:

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

The controls attribute adds playback controls to the audio element.

The <source> element specifies the URL of the audio file and its MIME type.

The text Your browser does not support the audio tag is displayed if the browser does not support the audio tag.

Try Playground

Audio Attributes

The <audio> tag has several attributes that can be used to customize the behavior and appearance of the audio element. Here are some of the most commonly used audio attributes:

  1. src: Specifies the URL of the audio file.
  2. controls: Adds playback controls to the audio element.
  3. autoplay: Specifies that the audio should start playing automatically when the page loads.
  4. loop: Specifies that the audio should play in a loop.
  5. muted: Specifies that the audio should be muted by default.

Using the Audio Tag with CSS

CSS can be used to style the <audio> tag and its contents. Here is an example of how to style an audio element using CSS:

audio {
  border: 5px solid black;
  margin: 10px;
}

Importance of the Audio Tag

  • The <audio> tag can be used to play audio on a web page without the need for a third-party plugin.
  • The <audio> tag can help to improve the user experience of a web page.
  • Search engines use the <audio> tag to index the structure and content of web pages.
Try Playground
Published on: