programminghead Logo

Background Audio - Using BgSound SRC Sound mp3 Loop

These HTML Attributes ( BgSound SRC Sound mp3 Loop ) Allow us to add, Loop and play an Audio/Sound in the Background. We just need to Give Audio/Sound file's path using HTML "SRC" attribute. So browser can get the Audio/Sound file from the Given path the perform the rest Given Tasks like :
Looping and
Auto playing in the Background.

BgSound SRC Sound mp3 Loop (Example)


      <title>HTML bgsound (With Loop)</title>

      <bgsound src = "audio.mp3" loop="infinite"/>



BGsound Tag : <bgsound>

HTML BGsound Tag (<bgsound>) allow users to add Background Sounds to HTML Documents. Which can run in the Background on Page Load.

SRC Attribute : <bgsound src=""/>

HTML SRC Attribute (<src="source">) assigns Path so Browser can Get the Audio file from the Given Source and Perform the Tasks.

LOOP Attribute : <bgsound loop/>

HTML Loop Attribute (<loop="loopTimes">) Allow Audio to play Multiples time. We can Loop an Audio file According to our Needs.
If we want to loop an Audio file 5 Times, Then we can specify 5 in Loop Attribute (<loop="5">) or if we want to Loop an Audio file Again and Again to Infinite we can do that by writing Infinite in Loop Attribute (<loop="infinite">).

bgsound src sound mp3 loop 1

Background Audio not Playing Automaticly?

If your Background audio is not Playing automatically, Then this can be happening because of the Browser you are using. Due to security reasons Some browser Prevent automated Tasked and blocks them and returns Error like : Uncaught (in promise).
To fix this we can use IFRAME.
By using iframe we can add Audio in the Background and Run/Play the audio automatically.

Background Audio using IFrame (Autoplay Works)


      <title>HTML Background Sound</title>

        <iframe src="audio.mp3" allow="autoplay" style="display:none"></iframe>


SRC Attribute : <bgsound src="file'sPath"/>

HTML SRC Attribute (<src="source">) assigns Path so Browser can Get the Audio file from the Given Source and Perform the Tasks.

Allow Attribute : <allow="autoplay"/>

Allow Attribute (<allow="autoplay">) allows iframe's features like Autoplay. So audio or sound can Play Automatically.

style Attribute : <style="display:none"/>

HTML style Attribute (<style="display:none">) used for applying Style/CSS to HTML Elements. Here we are using "Display:none" Style/CSS Property, So we can Hide the iframe Element so audio can Run the in Background.

If you are Facing Problems, Please write to us Using this Page's Comment Section. We will Respond and try to Fix your Problem as Soon as Possible.



06:59 pm

looping not working in this code???? pls help me <iframe src="mysong1.mp3" allow="autoplay" id="audio" style="display:none" loop="infinite"></iframe> <iframe src="audio.mp3" allow="autoplay" style="display:none"></iframe>


Thanks For your Comment.
Sir, You are using IFRAME Method to Play a Audio file in Background. But if you want to loop your Audio file in Background then you can't do that with "ifame"

To Autoplay play Audio file in Background with Audio Loop then you have to Use This Little Trick (Using Audio Tag to Loop Audio in Background).

Click the Blue Link to Check out Our Method to play Audio in Background with Loop.


02:38 pm

Iframe method Worked for me. THANKS


thanks for visiting our Website

Write to Us