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

How to add background music in web page?

I want to add background music that autoplays when a person opens the website. When I try to embed it, the audio file shows up on the browser and I have to manually play the music. I'm new to this and haven't learnt javascript yet. I have to submit it tomorrow can anyone tell me how to do it?

22nd Oct 2019, 3:42 PM
Dua Batool
Dua Batool - avatar
2 Answers
+ 1
<audio preload="auto" autoplay src="music.mp3"></audio> Or <iframe src="music.mp3" allow="autoplay" id="audio" style="display: none;"></iframe> Or <script> let music = new Audio(); music.preload = "auto"; music.src = "music.mp3"; music.autoplay = "true"; </script>
22nd Oct 2019, 4:32 PM
Jônatas Araripe
Jônatas Araripe - avatar