What Is The HTML Audio

The HTML Audio component is utilized to play a sound document on a website page.

The HTML <audio> Element

To play a sound document in HTML, utilize the <audio> element:

Example

<audio controls>
  <source src=”horse.ogg” type=”audio/ogg”>
  <source src=”horse.mp3″ type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>

HTML Audio – How It Works

The controls trait adds sound controls, similar to play, interruption, and volume.

The <source> component permits you to determine elective sound records which the program might look over. The program will utilize the main perceived arrangement.

The content between the <audio> and </audio> labels might be shown in programs that don’t uphold the <audio> element.

HTML <audio> Autoplay

To begin a sound document consequently, utilize the autoplay property:

Example

<audio controls autoplay>
  <source src=”horse.ogg” type=”audio/ogg”>
  <source src=”horse.mp3″ type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>

Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.

Add quieted after autoplay to allow your sound to record begin playing naturally (yet quieted):

Example

<audio controls autoplay muted>
  <source src=”horse.ogg” type=”audio/ogg”>
  <source src=”horse.mp3″ type=”audio/mpeg”>
Your browser does not support the audio element.
</audio>

Browser Support

The numbers in the table determine the main program form that completely upholds the

HTML Audio
HTML Audio

HTML Audio Formats

There are three upheld sound arrangements: MP3, WAV, and OGG. The program support for the various configurations is:

BrowserMP3WAVOGG
Edge/IEYESYES*YES*
ChromeYESYESYES
FirefoxYESYESYES
SafariYESYESNO
OperaYESYESYES
HTML Audio

HTML Audio – Media Types

File FormatMedia Type
MP3audio/mpeg
OGGaudio/ogg
WAVaudio/wav
HTML Audio

HTML Audio – Methods, Properties, and Events

The HTML DOM characterizes strategies, properties, and occasions for the<audio> element.

This permits you to load, play, and respite sounds, just as set term and volume.

There are likewise DOM occasions that can inform you when a sound starts to play, is stopped, and so on.

For a full DOM reference, go to our HTML Audio/Video DOM Reference.

HTML Audio Tags

TagDescription
<audio>Defines sound content
<source>Defines multiple media resources for media elements, such as <video> and <audio>
HTML Audio