HTML Audio Tag

Last Updated On Sunday 22nd May 2022

audio html

The <audio> HTML element is used to embed sound content in documents or play an audio file on a web page.

	<audio controls>
  <source src="cj.mp3" type="audio/mpeg" />
</audio>
	

html5 audio player

  • 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 content inside the opening and closing <audio> </audio> tags is shown as a fallback in browsers that don’t support the element.

	<audio controls>
  <source src="cj.mp3" type="audio/mpeg" />
  Your Browser not Supports audio tag
</audio>
	

html audio

HTML <audio> Autoplay

	<audio controls autoplay>
  <source src="cj.mp3" type="audio/mpeg" />
  Your Browser not Supports audio tag
</audio>
	
  • Adding autoplay to let your audio start playing automatically

audio in html

	<audio controls autoplay muted>
  <source src="cj.mp3" type="audio/mpeg" />
  Your Browser not Supports audio tag
</audio>
	
  • Add muted after autoplay to let your audio start playing automatically

playing audio html

Some Important Audio Tag Attributes

  • autoplay – A Boolean attribute, audio automatically begins to play.
  • controls – It allows the user to control audio playback, including volume, seeking, and pause/resume playback.
  • crossorigin – It indicates whether to use CORS to fetch the related audio.
  • loop – The browser will automatically seek back to the start reach the end of the audio.
  • src – The URL of the audio to embed. You may instead use the <source> element within the audio block to specify the audio to embed.
  • disableremoteplayback – Used to disable the capability of remote playback in devices that are attached using wired and wireless technologies
  • muted – The audio will be initially silenced

html audio player

Browser Support

Browsers Chrome Edge Mozilla Safari Opera
<audio> 4.0 9.0 3.5 4.0 10.5