HTML Bgsound Tag

The <bgsound> tag is used to automatically play a background sound when a web page loads. The idea behind <bgsound> was to embed background music or sound effects in a webpage without the user having to click anything. The sound would start playing as soon as the page loaded and could even be looped.

Syntax -

The <bgsound> tag is a self-closing tag. It uses attributes to control the audio.

<bgsound src="soundfile.mp3" loop="infinite">
AttributeDescription
SrcSpecifies the path to the sound file you want to play.
LoopDefines how many times the sound should play. Use "infinite" for looping forever or a number like "3" to repeat it 3 times.
Volume(Only in some versions) Sets the volume level, but browser support is very limited. The value is between -10000 and 0
Example -

Scenario - example of how it was used in old-school HTML

<!DOCTYPE html>
<html>
	<head>
		<title>Bgsound tag example..</title>
	</head>
	<body>
		<bgsound src="audio/new.mpg loop="infinite"">
	</body>
</html>
Output -

bgsound tag not supported in this browser.

Explaining Example -

What happens here:

  • As soon as the page loads, the music file new.mp3 starts playing.
  • It will loop forever unless stopped.
  • This will only work in Internet Explorer or legacy browsers.