Audio Tags in HTML5


Audio tag is used to define sounds such as music and other audio clips. Currently there are three supported file format for HTML 5 audio tag.

  • mp3
  • wav
  • ogg

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.

To start an audio file automatically, use the autoplay attribute. Add muted after autoplay to let your audio file start playing automatically (but muted)

Example :

<!DOCTYPE html>
<html>
	<head>
		<title>HTML5 - Tutor Joes</title>
	</head>
	<body>
	<h3>mp3 format file</h3>
		<audio controls>
			<source src="music.mp3" type="audio/mp3">
		</audio>
	<h3>ogg format file</h3>
		<audio controls autoplay>
			<source src="music.ogg" type="audio/ogg">
		</audio>
	<h3>wav format file</h3>
		<audio controls autoplay muted>
			<source src="music.wav" type="audio/wav">
		</audio>
	</body>
</html>

Output :

HTML Audio Tag