How to add background music to your web page? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

How to add background music to your web page?

How to add background music to your web page?

15th Jun 2020, 8:12 AM
Shahid Gul
Shahid Gul - avatar
27 Answers
+ 14
Shahid Gul try this👇 HTML: <audio id = "Any name"> <source src = "audio link "> </audio> JS: window.addEventListener('click', function () { var audio = document.getElementById("Any name"); audio.play(); } click screen to hear the music👍
16th Jun 2020, 12:37 PM
Simba
Simba - avatar
+ 12
I think this code check <embed name="myMusic" src="Masgon.mp3" type="audio/midi" autostart="false" Hidden="true" loop="true"></embed> 
16th Jun 2020, 2:43 AM
IRONMAN
+ 6
I hope this help , kindly up-vote if it does; <audio autoplay loop> <Source src="you audio source on your comp.mp3" type="audio/mp3> Your browser does not support audio file! </audio> Ps: you can use the source tag for different audio type , so if one doesn't load on the website another type will load
15th Jun 2020, 12:51 PM
AKANDE OLUWATOSIN TEMITOPE
AKANDE OLUWATOSIN TEMITOPE - avatar
+ 6
Like this👇 <audio autoplay>   <source src="horse.ogg" type="audio/ogg">   <source src="horse.mp3" type="audio/mpeg"> </audio> If you want to add controls for audio, add "controls" into audio tag.
16th Jun 2020, 1:45 PM
Sahan Dakshitha
Sahan Dakshitha - avatar
+ 5
make sure your audio is supported by the browser and don't use internet explorer for your projects because it does not support alot of web programming features I suggest using google chrome because it has the fastest javascript engine V8.
16th Jun 2020, 3:04 PM
moses
moses - avatar
+ 5
<audio type="a. mp3" controls autoplay loop></audio>
17th Jun 2020, 12:15 AM
Pranjal Gupta
Pranjal Gupta - avatar
+ 4
try this: <body onload="play()"> <audio loop= 'true'> <source src="yourAudio.mp3" type="audio/mp3"> </audio> <script> let x = document.querySelector('audio'); function play(){ x.play(); } </script> </body>
16th Jun 2020, 3:01 PM
moses
moses - avatar
+ 3
Simba worked
16th Jun 2020, 5:14 PM
Shahid Gul
Shahid Gul - avatar
+ 3
Shahid Gul I suggest you to look at the Excellent answer by Calviղ
17th Jun 2020, 7:20 AM
Coder
Coder - avatar
15th Jun 2020, 8:18 AM
Calviղ
Calviղ - avatar
+ 2
https://www.sololearn.com/Discuss/159891/?ref=app
15th Jun 2020, 8:19 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 2
Do a simple thing using audio tag play you music without controls . Using loop and autoplay
15th Jun 2020, 8:38 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
ironman not working bro
16th Jun 2020, 8:40 AM
Shahid Gul
Shahid Gul - avatar
15th Jun 2020, 8:54 AM
Shahid Gul
Shahid Gul - avatar
+ 1
please inform me if it doesn't work and the audio enter your own audio with the appropriate file extension
16th Jun 2020, 3:05 PM
moses
moses - avatar
+ 1
follow me for more!
16th Jun 2020, 5:15 PM
moses
moses - avatar
+ 1
moses sure..
16th Jun 2020, 5:17 PM
Shahid Gul
Shahid Gul - avatar
+ 1
audio tag
16th Jun 2020, 6:49 PM
Asaad
Asaad - avatar
+ 1
<audio controls> <source src="audio.mp3" type="audio/mpeg"> <source src="audio.ogg" type="audio/ogg"> Audio element not supported by your browser. </audio>
17th Jun 2020, 1:07 AM
Richard Rodríguez
Richard Rodríguez - avatar
+ 1
Pranjal Gupta autoplay is not working.. autoplay is disabled in chrome Firefox browsers.. we need to add j.s to enable autoplay
17th Jun 2020, 5:48 AM
Shahid Gul
Shahid Gul - avatar