top of page

The HTML <audio> Element

 

To play an audio file in HTML, use 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 attribute adds audio controls, like play, pause, and volume.

 

The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.

 

The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.

HTML Audio Formats

There are three supported audio formats: MP3, WAV, and OGG. The browser support for the different formats is:

 

 

 

 

 

 

 

HTML Audio - Media Types

 

 

 

 

 

HTML Audio - Methods, Properties, and Events

The HTML DOM defines methods, properties, and events for the <audio> element.

 

This allows you to load, play, and pause audios, as well as set duration and volume.

 

There are also DOM events that can notify you when an audio begins to play, is paused, etc.

HTML Audio Tags

 

 

 

51.PNG
52.PNG
53.PNG

© 2020 by Web Laboratory Instructor Guide. Proudly created with Wix.com

bottom of page