HTML Audio


The <audio> element in HTML is used to play sound on a webpage.


The HTML <audio> Element

To include an audio file in HTML, employ the element:


HTML Audio - How It Works

The controls attribute includes audio features such as play, pause, and volume.

The <source> element lets you pick different audio files that the browser can choose from. The browser will use the first format it recognizes.

The content enclosed by the <audio> and </audio> tags will appear solely on browsers that do not have compatibility with the <audio> element.


HTML <audio> Autoplay

To make an audio file play automatically, simply add the autoplay attribute:


Insert muted after autoplay following "autoplay" to enable your audio file to start playing automatically, but with no sound:


HTML Audio - Methods, Properties, and Events

The HTML DOM has instructions, features, and triggers for the <audio> element.

You can use this code to load, play, and pause audio. Additionally, you can set the duration and volume as needed.

You can use DOM events to be alerted when audio starts playing, pauses, and more.


HTML Audio Tags

Tag Description
<audio> Defines sound content
<source> Describes various media sources for media elements like <video> and <audio>.